If you do not have control over the server
I had this problem and managed to get around it.
First connect to your MySQL database with an older client that doesn't mind old_passwords. Connect using the user that the script will use.
Run these queries:
SET SESSION old_passwords=FALSE; SET PASSWORD = PASSWORD('[your password]');
In your PHP script, change the mysql_connect function to enable client 1 flag:
define('CLIENT_LONG_PASSWORD', 1); mysql_connect('[your server]', '[your username]', '[your password]', false, CLIENT_LONG_PASSWORD);
This allowed me to connect successfully.
Edit: according to a comment in Garland Pope , it may not be necessary to manually set CLIENT_LONG_PASSWORD in your PHP code with PHP 5.4!
Edit: courtesy of Antonio Bonifati , a PHP script to run queries for you:
<?php const DB = [ 'host' => '...', # localhost may not work on some hosting 'user' => '...', 'pwd' => '...', ]; if (!mysql_connect(DB['host'], DB['user'], DB['pwd'])) { die(mysql_error()); } if (!mysql_query($query = 'SET SESSION old_passwords=FALSE')) { die($query); } if (!mysql_query($query = "SET PASSWORD = PASSWORD('" . DB['pwd'] . "')")) { die($query); } echo "Excellent, mysqli will now work"; ?>
TehShrike May 25 '10 at 3:01 2010-05-25 03:01
source share