|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62390 localhost x
Submitted: 2012-06-22 02:58 UTC Modified: 2012-06-25 17:31 UTC
From: rbnsjnr at gmail dot com Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 5.4.4 OS: Linux-3.2.21 Debian/Wheezy
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: rbnsjnr at gmail dot com
New email:
PHP Version: OS:


 [2012-06-22 02:58 UTC] rbnsjnr at gmail dot com
Dear (a) With PHP5.4.4 my projects do not connect more in the mysql database. I could not find answers on the Internet.

The PHP5.4.4 is not connecting to the mysql database with the function mysql_connect () and the parameter "localhost". When using the parameter "", this function connects without problem.

See the example below that the error does not return PHP5.4.3 and PHP5.4.4 returns an error.

Note: My PHP5.4.3 and 5.4.4 were compiled with the following parameters:

--prefix=/opt/php-5.4.3 --with-apxs2=/opt/httpd-2.4.2/bin/apxs --with-mysql --with-pgsql=/opt/PostgreSQL/9.0/ --with-zlib --with-bz2 --with-openssl --with-kerberos --enable-calendar --enable-ftp --enable-intl --enable-soap --enable-sockets --enable-zip

--prefix=/opt/php-5.4.4 --with-apxs2=/opt/httpd-2.2.22/bin/apxs --with-mysql --with-pgsql=/opt/PostgreSQL/9.0/ --with-zlib --with-bz2 --with-openssl --with-kerberos --enable-calendar --enable-ftp --enable-intl --enable-soap --enable-sockets --enable-zip

Test script:

$con = mysql_connect("localhost","u_joomlades","u_joomlades");
if (!$con) 
 die('Could not connect: ' . mysql_error());
 echo "\n";

echo "\n";


Expected result:
Replacing the parameter "localhost" to "" the PHP5.4.4 connects without problems.

rubens@debian:~$ /opt/php-5.4.3/bin/php bd.php 

rubens@debian:~$ /opt/php-5.4.4/bin/php bd.php 


Actual result:
rubens@debian:~$ /opt/php-5.4.3/bin/php bd.php 

rubens@debian:~$ /opt/php-5.4.4/bin/php bd.php 

Warning: mysql_connect(): No such file or directory in /home/rubens/bd.php on line 3
Could not connect: No such file or directory



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-06-22 11:23 UTC]
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

When using localhost it won't try connecting using TCP/IP but using a Unix Domain Socket. By default it expects the socket file to be /tmp/mysql.sock. If that's not your socket location youhave to use the --with-mysql-sock configure option or set mysql.default_socket, mysqli.default_socket and pdo_mysql.default_socket in php.ini or use a specific socket using i.e. mysql_connect(":/path/to/socket", "user", "pass");

You can find the socket location fromyour my.cnf file or by doing something like
  mysql_connect("", "root", "");
  $r = mysql_query("SHOW VARIABLES LIKE 'socket'");

Please mind that using mysql_* functions from the "mysql" extension is not suggested anymore. You should migrate to either mysqli or PDO.
 [2012-06-22 11:23 UTC]
-Status: Open +Status: Not a bug
 [2012-06-25 17:31 UTC] rbnsjnr at gmail dot com
Hello Johannes,
I believed it would be because bug with PHP 5.4.3 and 5.4.4 does not connect normally connects.

I will try to understand better about sockets, mysqli or pdo.

Anyway, thank you for your attention and support.

I wish you a great weekend and happy Saturday.

NOTE-1: I am using the google translator, it may be that there is any phrase that would not be legal in translation.

NOTE-2: If the message [mysql_connect (): No such file or directory in / home / rubens / bd.php on line 3
Could not connect: No such file or directory] is the treatment of missing the file / tmp / mysql.sock is the suggestion that the message should be improved.
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC