Hello,
Am trying to fetch data from one table of one DB and put it into another DB's table.
I wrote below connection code for this:
<?php
$date = date('Y-m-d H:i:s');
/* OLD EIMS connection values */
$old_host= "localhost";
$old_uname="root";
$old_pass="ABC";
$old_database ="EIMS_OLD";
/* NEW EIMS connection values */
$new_host= "111.11.111";
$new_uname="root";
$new_pass="ABCD";
$new_database ="EIMS_REVAMP";
/* connection with logfile */
$file = fopen("/var/www/migration_logfile.txt","a+");
if(!$file)
echo " failed to open migration log file";
/* Connect with OLD EIMS */
$old_EIMS_connection = mysql_connect($old_host,$old_uname,$old_pass);
$old_EIMS_connection_link =mysql_select_db($old_database, $old_EIMS_connection);
/* Connect with New EIMS */
$new_EIMS_connection = mysql_connect($new_host,$new_uname,$new_pass);
$new_connection_link =mysql_select_db($new_database, $new_EIMS_connection);
if (!$old_EIMS_connection_link) {
fwrite($file,$date ." Connection failed with OLD EIMS -> error -> ".mysql_error());
fwrite($file,"\n");
die('Not connected : ' . mysql_error());
}
if (!$new_EIMS_connection) {
fwrite($file,$date ." Connection failed with NEW EIMS -> error -> ".mysql_error());
fwrite($file,"\n");
die('Not connected : ' . mysql_error());
}
else {
/* Query for University Table, import row by row */
$OLD_EIMS_university_query = mysql_query("SELECT * FROM university ",$old_EIMS_connection);
// Write in log if fails
if($OLD_EIMS_university_query==false){
fwrite($file,$date ." Could not run Select from University query: " . mysql_error());
}
else{ //insert values in new database table
while($row1 = mysql_fetch_row($OLD_EIMS_university_query))
{
$university_id= $row[0];
$university_name= $row[1];
$NEW_EIMS_query = mysql_query("INSERT INTO university ( university_id ,university_name ,created_at ,updated_at)
VALUES (".$university_id." , '".$university_name."', '".$date."', '".$date."')",$new_EIMS_connection);
if($NEW_EIMS_query==false){
fwrite($file,$date ." Could not run query for University Table insertion. Error: " . mysql_error());
fwrite($file,"\n");
echo 'Could not run query for University Table insertion. Error: ' . mysql_error();
echo "<br>";
}
}
}
/* Added this and stopped working */
/* Query for Collge Table, import row by row */
$OLD_EIMS_college_query = mysql_query("SELECT * FROM college ",$old_EIMS_connection);
// Write in log if fails
if($OLD_EIMS_college_query==false){
fwrite($file,$date ." Could not run Select from College query: " . mysql_error());
fwrite($file,"\n");
echo 'Could not run College Table select query. Error: ' . mysql_error();
}
else{ //insert values in new database table
// it returns $row2 false but not showing error
while($row2 = mysql_fetch_row($OLD_EIMS_college_query))
{
echo "am in while loop<br>";
$college_id= $row[0];
$college_name= $row[1];
$university_id= $row[4];
echo "college_id: ".$college_id. " college_name".$college_name . " university_id".$university_id ."<br>";
}
}
}
$conn->close();
?>
It was working everything till I have University in loop
It was showing errors, writting in file
but when I inserted College this this loop, it stopped working for both University and College
When I debug this, it shows me Resouce ID# i.e. it is connecting and fetching data.
but it not showing me what I echo.
Why so?
i removed college from loop still it is not showing any error.
Am i doing any mistk in this?