Bug #59348 | PHP mysql_connect - no resource id returned | ||
---|---|---|---|
Submitted: | 7 Jan 2011 11:27 | Modified: | 31 Jan 2011 9:14 |
Reporter: | Dave Walker | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | Connector / C | Severity: | S2 (Serious) |
Version: | 5.1.41 | OS: | Any |
Assigned to: | CPU Architecture: | Any | |
Tags: | mysql_connect |
[7 Jan 2011 11:27]
Dave Walker
[7 Jan 2011 12:16]
Valeriy Kravchuk
Are you able to connect successfully with mysql command line client to the same host, using the same user name and password?
[7 Jan 2011 18:46]
Dave Walker
Yes. PHP mysql_connect fails to return the resource id when using MySQL version 5.1.41 or greater (same when using any version of PHP). (the category is not correct: MySQL Connector/J, please change) Thanks
[7 Jan 2011 19:20]
Valeriy Kravchuk
For me everything works, by PHP manual: macbook-pro:trunk openxs$ php bug59348.php Connected successfully MySQL server version: 5.1.55-debug macbook-pro:trunk openxs$ cat bug59348.php <?php $link = mysql_connect('127.0.0.1', 'root', ''); if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; printf("\nMySQL server version: %s\n", mysql_get_server_info()); mysql_close($link); ?> macbook-pro:trunk openxs$ php --version PHP 5.2.6 (cli) (built: Oct 9 2008 22:44:00) Copyright (c) 1997-2008 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies What am I doing wrong?
[8 Jan 2011 9:30]
Dave Walker
Different outcome when run on Linux: <?php $link = mysql_connect('localhost', 'test', 'test'); if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; printf("\nMySQL server version: %s\n", mysql_get_server_info()); mysql_close($link); ?> Returns: ---------------------------------------------------------------------------- Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'test'@'localhost' (using password: YES) in /opt/lampp/htdocs/test.php on line 2 Could not connect: Access denied for user 'test'@'localhost' (using password: YES) ---------------------------------------------------------------------------- Whereas this: <?php $link = mysql_connect('localhost', 'test', 'test'); /*if (!$link) { die('Could not connect: ' . mysql_error()); }*/ echo 'Connected successfully'; printf("\nMySQL server version: %s\n", mysql_get_server_info()); mysql_close($link); ?> returns: ---------------------------------------------------------------------------- Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'test'@'localhost' (using password: YES) in /opt/lampp/htdocs/test.php on line 2 Connected successfully MySQL server version: 5.1.41 Warning: mysql_close() expects parameter 1 to be resource, boolean given in /opt/lampp/htdocs/test.php on line 8 ---------------------------------------------------------------------------- Ubuntu 10.04 LTS - the Lucid Lynx - PHP Version 5.3.1
[8 Jan 2011 10:12]
Valeriy Kravchuk
Then let me repeat my first question in a more specific form: Can you connect as 'test'@'localhost' with password 'test' from the command line mysql client?
[8 Jan 2011 12:48]
Dave Walker
Can you connect as 'test'@'localhost' with password 'test' from the command line mysql client? YES. Check the returns above the second one shows it connects and outputs the correct MySQL version: "Connected successfully MySQL server version: 5.1.41"
[8 Jan 2011 16:26]
Valeriy Kravchuk
But I still see this: Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'test'@'localhost' (using password: YES) in /opt/lampp/htdocs/test.php on line 2 So, I'd prefer to see a copy/paste of mysql command line call, like this: macbook-pro:5.1 openxs$ bin/mysql -uroot test Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.1.55-debug Source distribution Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. This software comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to modify and redistribute it under the GPL v2 license Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> select current_user(); +----------------+ | current_user() | +----------------+ | root@localhost | +----------------+ 1 row in set (0.00 sec) In any case, if you suspect a bug in libmysqlclient* used by PHP or in server, we need to check if it is repeatable with a recent version, 5.1.54.
[11 Jan 2011 12:25]
Dave Walker
OK, as requested, here is the output from the commandline: C:\wamp\bin\mysql\mysql5.1.41\bin>mysql -u tt Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 92 Server version: 5.1.41-community-log MySQL Community Server (GPL) Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> exit Bye C:\wamp\bin\mysql\mysql5.1.41\bin>mysql -u tt -p Enter password: ** ERROR 1045 (28000): Access denied for user 'tt'@'localhost' (using password: YES) ---------------------------------------------------------------------------------------- As you can see it connects using the username "tt" when no password is specified, the connection as "no" user: @localhost as opposed to when connected via "root" username: root@localhost User Host Password Global privileges 1 Grant root No ALL PRIVILEGES Yes test % Yes ALL PRIVILEGES Yes tt % Yes ALL PRIVILEGES Yes I have double checked the permissions, recreated the users, restarted the services and its still the same. Getting the same result on Windows Vista and Linux test machines. PHP mysql_connect gets a resource id when a the password is blank!
[24 Jan 2011 12:20]
Ulf Wendel
I fail to see an issue here. If connect fails and no error handling is done, PHP bails. That is just as it should be.
[31 Jan 2011 9:14]
Ulf Wendel
One of the sample scripts calls die() to stop execution, the other one does not. One bails a bit more as a follow-up of uninterrupted script execution (no die()) the other does not. Everything works as it should.