Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows 7 PHP MySQL Connection Issues [duplicate]

When I run $conn = mysql_connect($host, $user, $pass); I am able to get a connection to the database but when i do a var_dump($conn) I get back bool(true) which is limiting me from having multiple connection to multiple servers.

The original setup on this computer was XAMPP with a version of PHP 5.2 that was upgraded to PHP 5.3.4 via the PHP installer. It could connect to its local database with no problem (other than returning a boolean instead of the resource link identifier) but could not connect to any remote machines (and the ability to connect to remote machines has been confirmed). Without being able to come up with a solution, i upgraded to a version of XAMPP that has PHP 5.3.1 built in. I get exactly the same error after a fresh reinstall of XAMPP which is leading me to believe that this is a larger issue.

Edit 1 **

Moving to a clean install of windows and installing XAMPP and trying to run a mysql_connect to a remote server (PHP 5.3.1) i get the same error:

Warning: mysql_connect() [function.mysql-connect]: Premature end of data (mysqlnd_wireprotocol.c:554) in [Removed] on line 2

Warning: mysql_connect() [function.mysql-connect]: OK packet 1 bytes shorter than expected in [Removed]p on line 2

Warning: mysql_connect() [function.mysql-connect]: mysqlnd cannot connect to MySQL 4.1+ using the old insecure authentication. Please use an administration tool to reset your password with the command SET PASSWORD = PASSWORD('your_existing_password'). This will store a new, and more secure, hash value in mysql.user. If this user is used in other scripts executed by PHP 5.2 or earlier you might need to remove the old-passwords flag from your my.cnf file in [Removed] on line 2
like image 380
Geoffrey Wagner Avatar asked Dec 28 '22 02:12

Geoffrey Wagner


2 Answers

Check old_passwords option in your my.cnf file.

http://dev.mysql.com/doc/refman/5.0/en/server-options.html#option_mysqld_old-passwords

If for whatever reason you can't switch to new passwords, you can't use mysqlnd as your MySQL driver, and need to switch back to the older one.

Some more information about mysqlnd

http://dev.mysql.com/downloads/connector/php-mysqlnd/

like image 124
Mchl Avatar answered Jan 04 '23 22:01

Mchl


Regarding the error posted in your edit, I had been getting the same error on Windows 7 using PHP 5.3.5 when connecting to MySQL 5.0.45 on Linux. The solution for me was to disable "old_passwords" in my.cnf AND run

set password = password('my password');

The error message doesn't make it clear that you have to do both steps in order to fix the problem. Hope this helps.

like image 32
mmalone Avatar answered Jan 04 '23 23:01

mmalone