|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-07-09 13:51 UTC] michael dot kofler at gmx dot com
Description:
------------
neither mysql nor mysqli work at all
the problem is caused by mysqlnd (if I compile without mysqlnd, it works)
testing environment:
1) Linux with MySQL 5.1.25 and PHP 5.3 snapshot compiled with
--with-mysql=mysqlnd --with-mysqli=mysqlnd
2) Windows Vista with MySQL 5.1.25 and PHP 5.3 snapshot
in both cases, phpinfo() shows mysql, mysqli and mysqlnd information; mysql and mysqli use mysqlnd
Reproduce code:
---------------
$mysqli = new mysqli("localhost", "root", "***", "mydatabase");
Expected result:
----------------
a valid mysqli object (code works in Windows with PHP 5.2.6 and in Linux when PHP is compiled without mysqlnd)
Actual result:
--------------
Windows: blank page, no error at all
Linux:
Warning: mysqli::mysqli() [mysqli.mysqli]: [2002] No such file or directory ...
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 08:00:01 2025 UTC |
re-tested on Linux with alpha1, compiled with this configuration: configure --with-mysqli=mysqlnd \ --with-mysql=mysqlnd \ --with-mysql-sock=/var/run/mysqld/mysqld.sock \ --enable-pdo \ --with-pdo-mysql=mysqlnd \ --with-apxs2=/usr/bin/apxs2 \ --with-zlib \ --with-gd \ --with-config-file-scan-dir=/etc/php5/apache2 \ --with-jpeg-dir=/usr/lib \ --enable-exif \ --libdir=/usr/lib \ --enable-mbstring also tried --with-mysql-sock=/var/run/mysqld \ result: mysql, mysqli and PDO/mysql, all using mysqlnd, still look for the socket file /tmp/mysql.sock and ignore --with-mysql-sock if I compile without mysqlnd and without the --with-mysql-sock option, PHP automatically finds the right socket file, probably because libmysql reads the [client] settings in /etc/mysql/my.cnf my solution for now: I changed all socket options in /etc/mysql/my.cnf and /etc/mysql/debian.cnf it would be better either to provide a working configure option for PHP (--mysqlnd-sock=...) or to evaluate my.cnf within mysqlnd ------ PS: as to mysqlnd not supporting old MySQL authentication: perfectly fine for me, but *do document* it in some PHP 5.3 update advisory; otherwise I am pretty sure the update to PHP 5.3 will cause trouble for many MySQL usersHi, it was a problem, the Unix path, in the extensions, not mysqlnd. Yes, mysqlnd uses /tmp/mysql.sock, but actually there are no configure options for mysqlnd. --with-mysql-sock is actually an option of ext/mysql . It wasn't used in the past, as far as I recall, but current 5_3 and HEAD do use it to set default value for the socket path, which can be overwritten by the user. Both for ext/mysql and mysqli. This if from ext/mysql/php_mysql.c : #ifdef MYSQL_UNIX_ADDR STD_PHP_INI_ENTRY("mysql.default_socket", MYSQL_UNIX_ADDR,PHP_INI_ALL,OnUpdateStringUnempty, default_socket, zend_mysql_globals, mysql_globals) #else STD_PHP_INI_ENTRY("mysql.default_socket", NULL, PHP_INI_ALL, OnUpdateStringUnempty, default_socket, zend_mysql_globals, mysql_globals) #endif This is from ext/mysqli/mysql.c : #ifdef PHP_MYSQL_UNIX_SOCK_ADDR STD_PHP_INI_ENTRY("mysqli.default_socket", MYSQL_UNIX_ADDR,PHP_INI_ALL,OnUpdateStringUnempty, default_socket, zend_mysqli_globals, mysqli_globals) #else STD_PHP_INI_ENTRY("mysqli.default_socket", NULL, PHP_INI_ALL, OnUpdateStringUnempty, default_socket, zend_mysqli_globals, mysqli_globals) #endif MYSQL_UNIX_ADDR is a macro, for PHP_MYSQL_UNIX_ADDR, which is defined by the configure script if --with-mysql-sock is used. In this regard, PDO doesn't use --with-mysql-sock. PDO_MYSQL used mysql_config to find the socket, but for mysqln defaults to /tmp/mysql.sock , which seems like bug, because of inconsistency. This is something for Johannes Best, AndreyThis is clearly a bug: # sapi/cli/php -n -r 'mysql_connect("localhost:3306");' Output with --with-mysql=mysqlnd: Warning: mysql_connect(): [2002] No such file or directory (trying to connect via unix:///tmp/mysql.sock) in Command line code on line 1 # sapi/cli/php -n -r 'mysql_connect("localhost:3306");' No output (error) --with-mysql (without mysqlnd) -> connection works. The problem is with code in ext/mysqlnd/mysqlnd.c:537-543 which forces using the socket in this case. Note: Same happens with mysqli. This bug also makes all mysql(i) tests fail unless one uses some environment variables while running them.Jani, I think you are wrong : andrey@winnie:/work/vanilla/php/php-src/branches/PHP_5_3$ ./php -r '$c=mysql_connect("localhost:3307");var_dump($c, $res=mysql_query("select 42", $c), mysql_fetch_assoc($res));' Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in Command line code on line 1 Warning: mysql_query() expects parameter 2 to be resource, boolean given in Command line code on line 1 Warning: mysql_fetch_assoc() expects parameter 1 to be resource, null given in Command line code on line 1 bool(false) NULL NULL --------------------------- My MySQL runs on 3307 and the socket it uses is /tmp/mysql.sock. I have a /etc/my.cnf, that specifies /var/run/mysqld/mysqld.sock, and the client tries to use it. So you see, if you specify localhost this means - use unix socket, no matter if there is a port or not. mysqlnd does the same. Same is valid if you try mysql --host localhost --port=3307 . I suppose in your case you had mysql running with socket which you was where expected.PHP Warning: mysql_connect(): [2002] A connection attempt failed because the connected party did not (trying to connect via tcp://localhost:3306) in C:\inetpub\wwwroot\test.php on line 3 I got this error on running my php file:test.php <?php echo "Got it............test.php"; $con=mysql_connect("localhost","root","pa@onicz"); if(!$con) die('Could not connect: '.mysql_error()); echo "Connection Success"; ?> I am working on windows 7 + IIS 7 + php 5.3.3 + MySQL 5.1.53 Someone please help me...