Migrating code from PHP4 to PHP5

liunx

Guest
I'm not a developer and was hoping to get some help. There's an existing website (on a single box running Linux, Apache, PHP 4.1.2, MySQL 3.23.58) that I need to migrate over to another setup (2 boxes, the web/app server running MS 2003 Server, IIS6, PHP 5.2.4 and a DB box running on SuSE, MySQL 5.0.26). I've gotten the connection between the two new boxes to work, but a lot of the code from the original website doesn't seem to work.

Is there anything obvious I should know about migrating code from the older setup to the newer one, which is running different versions of PHP and MySQL. I've attached 2 php files (both renamed to txt). When I bring up the dir_master.php file, the only thing that comes up is the Name, Affiliation, and Department headers from the contents.php file.... nothing gets displayed from the MySQL database. Like I said, I have been able to pull stuff out of the DB using code I wrote myself to test it, so I'm sure the PHP to MySQL connection is working.

I think the issue might be with the PHP code and how the HTML is embedded in it, but like I said, this isn't my field of expertise. Looking at the code, is there anything obvious I can change without having to rewrite everything? I'm hoping there's a quick syntax fix.... especially since there's a number of PHP files that will need to get changed.

I could backrev the server to PHP4, I'm just not sure if I'll run into any issues with PHP4 connecting to a MySQL 5 server. Any advice on that front? Any known issues with that setup? Plus I saw that they're dropping support on PHP4 soon, so I'm not sure if backreving makes sense. I don't really have a lot of time to spend on this, so any suggestions on what might be the easiest way to get this up and working would be greatly appreciated.

Hopefully someone can point me in the right direction.
TIAYou might want to add a couple lines to the top of your script to make sure you're seeing any error messages PHP has to tell you where the problem is. Hopefully it will help narrow down the search. (My guess is something in the db_connect.php file.)

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);

include("db_connect.php");

$query = "SELECT * FROM directory order by Name";

$result = mysql_query($query);
echo $result
$num=mysql_numrows($result);

mysql_close();

$headline = "MASTER DIRECTORY";
include("contents.php");

?>You have an obvious syntax error in the first file

<?php
include("db_connect.php");

$query = "SELECT * FROM directory order by Name";

$result = mysql_query($query);
echo $result // error here - no ;
$num=mysql_numrows($result);

mysql_close();

$headline = "MASTER DIRECTORY";
include("contents.php");

?>


Also, echo $result; will not produce any meaningful output. At the very least you would need to

print_r($result);

to see what the query returned.As to php4 -> 5

too many differences to be listing here.

Probably one of the biggest sucker-traps will be the register_globals() setting anyway, which applies to both versions. If the original code was written by an idiot it will be relying on things like register_globals being ON, etc, etc.

Before you do anything else, run phpinfo() on both servers and compare the settings, note any differences and look up their significance.<?php

$query = "SELECT * FROM directory order by Name";

$result = mysql_query($query);
echo $result;
$num=mysql_numrows($result);

mysql_close();

$i=0;
while ($i < $num) {

$name=mysql_result($result,$i,"Name");
$affiliation=mysql_result($result,$i,"Affiliation");
$department=mysql_result($result,$i,"Department");
$id=mysql_result($result,$i,"id");

?>
<tr bgcolor="">
<td height="22" align="left"><b><a href=http://www.phpbuilder.com/board/archive/index.php/"http://mywebsite/bio.php?id=<?=$id?>" target="_blank" class="maintextboldlink"><?=$name?></a></b></td>
<td class="maintext"><?=$affiliation?></td>
<td class="maintext"><?=$department?></td>
</tr>'
<?php

$i++;
}

?>
A maybe stupid question from a mysql illiterate.
I wonder, you close mysql, in middle of script.
Maybe this is okay, as this script works in your old place?

Also there is no semicolon after: echo $result
but I am sure this is only in your webcopy of your script.
 
Back
Top