distracted Posted November 25, 2007 Share Posted November 25, 2007 im just starting to try php and mysql... i have the standard php, mysql, apache platform now... i already configured my mysql according to some tutorials... but when i try to connect php to my database an error always occur... this message appear on the error... Could not connect: Client does not support authentication protocol requested by server; consider upgrading MySQL client i used this code to try to connect to my database... <?php $link = mysql_connect('localhost', 'root', 'root'); if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_close($link); ?> i tried to upgrade mysql but same problem came out... what should i do... or is there sumthing im missin? thnak you... Quote Link to comment https://forums.phpfreaks.com/topic/78771-how-to-connect-php-to-mysql/ Share on other sites More sharing options...
BenInBlack Posted November 25, 2007 Share Posted November 25, 2007 Try this code Note: the function take the sql statement and returns and indexed associative array, this way your get the data and close the db connection and have a nice why of dealing the the data so let say the customer table has ID, Name, Address and Phone fields so in the example below $queryResults[0]['Name'] would return the first record Name field value <? function selectSQL($theQuery) { $openlink = mysql_connect($GLOBALS["dbhost"], $GLOBALS["dbuser"], $GLOBALS["dbpass"]) or die ("failed to connect to server: " . mysql_error()); mysql_select_db ($GLOBALS["db"]) or die ("failed to connect to database ($db): " . mysql_error()); $query = mysql_query($theQuery) or die ("Select query failed: " . mysql_error()); $array_counter = 0; $return_array = array(); while ($row = mysql_fetch_assoc ($query)) { foreach ($row as $key => $value) { $return_array[$array_counter][$key] = $value; } $array_counter++; } mysql_free_result ($query); return $return_array; mysql_close($openlink) or die ("couldn't clean up connection: " . mysql_error()); } $dbhost = 'localhost'; $dbuser = 'user'; $dbpass = 'password'; $db = 'database_name'; $queryResults = selectSQL("select * from customer"); print_r($queryResults); ?> I find it so annoying to deal with intermingling database lookup and output logic. So that is why i included this big example Quote Link to comment https://forums.phpfreaks.com/topic/78771-how-to-connect-php-to-mysql/#findComment-398633 Share on other sites More sharing options...
~n[EO]n~ Posted November 25, 2007 Share Posted November 25, 2007 Got this from MySQL forum, a simple workaround MySQL 4.1 and up uses an authentication protocol based on a password hashing algorithm that is incompatible with that used by older clients. If you upgrade the server to 4.1, attempts to connect to it with an older client may fail with the following message: shell> mysql Client does not support authentication protocol requested by server; consider upgrading MySQL client To solve this problem, you should use one of the following approaches: * Upgrade all client programs to use a 4.1.1 or newer client library. * When connecting to the server with a pre-4.1 client program, use an account that still has a pre-4.1-style password. * Reset the password to pre-4.1 style for each user that needs to use a pre-4.1 client program. This can be done using the SET PASSWORD statement and the OLD_PASSWORD() function: mysql> SET PASSWORD FOR some_user@some_host = OLD_PASSWORD('{your old password here}'); eg. SET PASSWORD FOR root@localhost = OLD_PASSWORD ('password'); worked perfectly Quote Link to comment https://forums.phpfreaks.com/topic/78771-how-to-connect-php-to-mysql/#findComment-398635 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.