MySQL 5 X + PHP code ISSUE! AUGH!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jediman
Forum Newbie
Posts: 1
Joined: Fri Dec 16, 2005 2:01 pm

MySQL 5 X + PHP code ISSUE! AUGH!

Post by jediman »

I have some older code which allowed me (and still allows me) to connect to the older styleMySQL 3x and pre 4.1 series of MySQL. Now I get that annoying : consider upgrading client to be more compatible message when trying to use it under the MySQL 5, and using PHP 4x and 5x. Tried using the old passwords command in MySQL but that doesnt work for whatever reason.
Also, doing this under Windows XP off of IIS 6x.

Here is the basic code:

Code: Select all

<?php 
// Connecting, selecting database 
$link = mysql_connect('127.0.0.1', 'root', 'password') 
   or die('Could not connect: ' . mysql_error()); 
echo 'Connected successfully'; 
mysql_select_db('test') or die('Could not select database'); 

// Performing SQL query 
$query = 'SELECT * FROM news'; 
$result = mysql_query($query) or die('Query failed: ' . mysql_error()); 

// Printing results in HTML 
echo "<table>\n"; 
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { 
   echo "\t<tr>\n"; 
   foreach ($line as $col_value) { 
       echo "\t\t<td>$col_value</td>\n"; 
   } 
   echo "\t</tr>\n"; 
} 
echo "</table>\n"; 

// Free resultset 
mysql_free_result($result); 

// Closing connection 
mysql_close($link); 
?>
Any thoughts?
Whats the new structure look like? that was basically copied from the php.net site, and I havent been successful when doing searches for MySQL 5x + PHP specific coding.
Need to convert my old scripts.
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post by AKA Panama Jack »

It sounds like your Mysql Client needs to match the Mysql Server.

In otherwords if PHP 5 is compiled for the Mysql 4.1 client and you are trying to access a Mysql 3.x Server you will get a message like that. The Mysql Client and Server SHOULD match in version numbers if you want to prevent getting incompatable messages.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

Its a minefield...;)

Access to MySQL 4.1 or 5.0 should be via the Improved MySQL extension (mysqli). In short get PHP5, compile (or do a shared type compile) with the mysqli extension. Then use the mysqli functions as described in the PHP manual.

On Windows - its just as simple as downloading the PHP binary, setting up for IIS (or Apache if possible) and uncommenting the extension line for php_mysqli.dll (php_mysql.dll should still be there for MySQL 3 and 4.0 access).
Post Reply