Bangladeshi Softwares
Home - Download - Codes & Tutorials - Bangla IT Bibhag - Mobile - About Me

 


Connecting MySQL 4.1 with PHP 4.x


Step-1:
Say, you are currently using PHP 4.x and just upgraded your MySQL database server from 4.0 to MySQL 4.1. Now, you want to test the databse connection from a sample PHP page. Let's call it 'dbcon.php'. Have a look inside the sample 'dbcon.php' file:


<?php

/*
 * Author: Ahsanul Haque Shovon
 * Email: ahsanul.haque.shovon@gmail.com / ahsanul_haque_shovon@yahoo.com
 * Web: http://shovon.110mb.com
 */

$host_name = "localhost";
$user_name = "phpapp";
$password = "abcd";
$db_name = "bd_db";

mysql_connect($host_name, $user_name, $password) or
die("<font color=\"#E00000\">Couldn't connect to $host_name.</font>");

mysql_select_db($db_name) or
die("<font color=\"#E00000\">Couldn't select database $db_name.</font>");

echo("Successfully connected to $db_name@$host_name");

?>


Step-2:
Now try the above code within your development server and you will get the following error:




You might be thinking that the above code connected smoothly to MySQL Server 4.0 before. Well there is nothing wrong with the code. The MySQL version 4.1 uses an authentication protocol based on a password hashing algorithm which is supported in PHP 5 and up. Can't we use MySQL 4.1 with PHP 4.x ? Why not? You can still use the 16 bit password hashing algorithm.


Here is one kind of workaround, which seems the easiest way to me. Find other ways in http://dev.mysql.com/doc/mysql/en/Old_client.html


Login to the MySQL server shell as a root user, and then apply the following command to the specific user:
mysql>SET PASSWORD FOR phpapp@localhost=OLD_PASSWORD('abcd');
mysql>FLUSH PRIVILEGES;

Now try the code again and you will see something like this:




Other Helpful Resources:
http://dev.mysql.com/doc/mysql/en/Old_client.html
http://www.php.net/mysqli



 



©Ahsanul Haque Shovon
All rights reserved