Hi,
I have a puzzle here that I hope some one can help solve .
I'm trying to transfer data between 2 MySQL databases. There are a total of 2600 records in the source database.
I'm cocatinating some fields in the source table to be transfered to a single field in the second table.
What puzzles me is that the program stops at arounf 510 records. Any one know how to get around this problem?
Any help is appreciated.
The code is very simpel. No recursion, No excessive function calls.
I'vw tried this code on
PC running WinNT4.0/IIS5
PC ruuning Win4.0/Apache (Abriasoft package)
Apache/1.3.3 (Unix) PHP/3.0.9
and they all have the same proble at different degree.
Thanks,
red
The code looks like the following,
<?php
if ($HTTP_HOST == "localhost" || $HTTP_HOST == "127.0.0.1") {
$host="localhost";
$dbname="homedb";
$dbusername="homeuser";
$dbpassword="homepsw";
} else {
$host="localhost";
$dbname="server";
$dbusername="serveruser";
$dbpassword="serverpsw";
}
$dbsession = mysql_connect($host, $dbusername, $dbpassword) or die("Unable to connect to SQL server :".mysql_errno().": ".mysql_error());
mysql_select_db($dbname,$dbsession) or die("Unable to select database :".mysql_errno().": ".mysql_error());
$sqln="SELECT ID, REFID from sourceTable";
$n_result = mysql_query($sqln,$dbsession) or die ($sqln."<br>".mysql_errno().": ".mysql_error()."<br>");
$n_num = mysql_num_rows($n_result);
echo "<br> ROWS found = $n_num";
for ($i = 0; $i < $n_num; $i ++) {
$n_row = mysql_fetch_array($n_result); // retrieve the record set of referent
echo "<br>Transfer $i : data for ".$n_row[ID];
$t_result = mysql_query($sqlt,$dbsession) or die ($sqlt."<br>".mysql_errno().": ".mysql_error()."<br>");
$sqlm="SELECT ID, REFID, Fieldx, Fieldy from importtab where REFID='".$n_row[ID]."'";
$m_result = mysql_query($sqlm,$dbsession) or die ($sqlm."<br>".mysql_errno().": ".mysql_error()."<br>");
$m_num = mysql_num_rows($m_result);
echo "<br><b>Found $m_num children of ".$n_row[ID]."</b>";
$fc[0]="";
$fc[1]="";
for ($j=0; $j<$m_num; $j++) {
$m_row = mysql_fetch_array($m_result); // retrieve the record set of referent
if ($j == '0') {
$fc[0] = $m_row[ID];
} else {
$fc[1] .=$m_row[ID].",";
}
}
echo "<br>Fieldx =".$fc[0];
echo "<br>Fieldy =".$fc[1];
$sqlp="UPDATE targetTable set (Fieldx='".$fc[0]."', Fieldy='".$fc[1]."',) where REFID='".$n_row[ID]."'";
$p_result = mysql_query($sqlp,$dbsession) or die ($sqlp."<br>".mysql_errno().": ".mysql_error()."<br>");
mysql_free_result($m_result); /*I thought this migh help save some memeory */
}
?>