|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2005-02-23 15:53 UTC] subscription at nazarenko dot net
 Description:
------------
I am running MySQL 4.1.10 and PHP 5.0.3.
By default, on SuSE MySQL uses "/var/lib/mysql/mysql.sock".
I changed the location of the MySQL socket to "/srv/mysql/mysql.sock" in /etc/my.cnf and MySQL is fine with it.
In my php.ini I have set mysqli.default_socket to the new socket "/srv/mysql/mysql.sock".
Reproduce code:
---------------
The code:
$mysqli = mysqli_init();
$mysqli->real_connect('localhost', SQL_LOGIN, SQL_PASSWD);
produces the following warning:
mysqli::real_connect(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /srv/www/htdocs/index.php on line 10
Expected result:
----------------
Since the socket value was omitted, it is expected that PHP uses the default sockeet value from the php.ini file.
The error shows that the default socket value for MySQLi is ignored by PHP.
Actual result:
--------------
When I first run phpinfo() I got the following output:
Client API version       4.1.10
MYSQLI_SOCKET 	         /var/lib/mysql/mysql.sock
mysqli.default_socket    /srv/mysql/mysql.sock
This made 3 things clear:
1) mysqli.default_socket variable *IS* correctly read from php.ini
2) mysqli.default_socket variable is *IGNORED* by the PHP interpreter
3) there is some variable called MYSQLI_SOCKET which is still set to the "old-default" socket
I searched in the header files of MySQL and found a file called "/usr/include/mysql/mysql_version.h", which contained a line:
#define MYSQL_UNIX_ADDR   "/var/lib/mysql/mysql.sock"
I changed it to "/srv/mysql/mysql.sock" and recompiled PHP again.
This time phpinfo() gave the following output:
Client API version       4.1.10
MYSQLI_SOCKET 	         /srv/mysql/mysql.sock
mysqli.default_socket    /srv/mysql/mysql.sock
However, the problem was not gone!
mysqli_real_connect() was still trying to use the "hard-coded" (?) value from MySQL server "/var/lib/mysql/mysql.sock".
Adding --with-mysql-sock=/srv/mysql/mysql.sock to the configure options list did not help either. I guess this is by design as --with-mysql-sock is not a MySQLi related option anyway.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 01:00:01 2025 UTC | 
Tried the php5-200509070630 snapshot. The settings in the php.ini file are: error_reporting = E_ALL display_errors = On mysqli.default_socket = "/srv/mysql/mysql.sock" mysqli.default_host = localhost Used this code for testing: <? $db = mysqli_connect('','user','password'); var_dump($db); close ($db); echo "---------------------------\n"; $dbr = mysqli_init(); var_dump (mysqli_real_connect ($dbr, '', 'user', 'password')); mysqli_close($dbr); ?> This produces the following ouput: object(mysqli)#1 (0) --------------------------- Warning: mysqli_real_connect(): (HY000/2002): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) bool(false) So it confirms that mysqli_real_connect() is still ignoring the php.ini setting.Sorry, you comment is not true. Both mysql*_connect functions, if called this way: mysql_connect('','user','password') mysqli_connect('','user','password') do use mysql*.default_host/mysql*.default_socket from the php.ini. See my example with mysqli_connect() above. It is ONLY mysqli_real_connect() called this way: mysqli_real_connect($db_obj, '', 'user', 'password') that does not use the values from php.ini. Just to dismiss the argument completely I have tried setting all mysqli.default_* parameters in the php.ini to proper values (safe mode off) and then calling mysqli_real_connect() this way: $db=mysqli_init(); mysqli_real_connect($db); I am still connection error and see that the mysqli_real_connect() is trying to use the hard-coded socket value, which is different from the php.ini