php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32081 mysqli_real_connect(): mysqli.default_socket in php.ini has no effect
Submitted: 2005-02-23 15:53 UTC Modified: 2005-09-22 22:14 UTC
From: subscription at nazarenko dot net Assigned: iliaa (profile)
Status: Closed Package: MySQLi related
PHP Version: 5CVS-2005-09-08 OS: *
Private report: No CVE-ID: None
 [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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-02-25 01:00 UTC] iliaa@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 [2005-09-05 15:36 UTC] subscription at nazarenko dot net
I have to reopen this bug.
mysqli_connect() treats the mysqli.default_socket OK.

mysqli_real_connect() still takes the hardcoded value and ignores the php.ini setting
 [2005-09-07 11:40 UTC] subscription at nazarenko dot net
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.
 [2005-09-07 13:48 UTC] sniper@php.net
The defaults are only used if you don't pass any parameters to these connect functions.
 [2005-09-08 00:40 UTC] subscription at nazarenko dot net
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
 [2005-09-08 07:57 UTC] subscription at nazarenko dot net
As I specified it in my last comment, safe mode was off.

What I am trying to say is that in all the testing scenarios the socket was never speified in a function call and the behaviour of mysqli_connect() and mysqli_real_connect() is not the same.

mysql_connect() does use the mysqli.default_socket value and it does not matter if I specify user/password in a function call or not. 

mysqli_real_connect() never uses the mysqli.default_socket value, whether user/password are given in a function call or not.
 [2005-09-10 22:57 UTC] sniper@php.net
Assigning to Ilia who supposedly fixed something like this before..

 [2005-09-22 22:14 UTC] tony2001@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 11:01:30 2024 UTC