I have a live server and a test server right now, and I need to copy a table from live to test using cron because it needs to run every hour. I've created a php
script and tested it using localhost, and it works fine, but when I test at live server, it doesn't work.
I suspect because when at localhost, although it between different database but still using the same server connection. and I'm using phpmyadmin
.
Edit: Here the code
<?php
/* fill in your source database name */
$database = "xxx";
$dbhost1 = "xxx";
$dbusr1 = "xxx";
$dbpas1 = "xxx";
/* fill in your target database name */
$database2 = "yyy";
$dbhost2 = "yyy";
$dbusr2 = "yyy";
$dbpas2 = "yyy";
if ($connect = mysqli_connect($dbhost1, $dbusr1, $dbpas1))
{
mysql_select_db($database, $connect);
echo "connected to xxx<br/>";
}
else { die("Source database fail to connect: Please try again" . mysql_error());}
if ($connect2 = mysqli_connect($dbhost2, $dbusr2, $dbpas2))
{
mysql_select_db($database2, $connect2);
echo "connected to yyy<br/>";
}
else { die("Target database fail to connect 1: " . mysql_error());}
set_time_limit(0);
$tables = array("coupon");
$tables_no = count($tables);
for ($i=0; $i < $tables_no ; $i++){
$tab = $tables[$i];
$query_table1 = "SELECT * FROM $database.$tab";
$query_table2 = "SELECT * FROM $database2.$tab";
$source= mysql_query($query_table1);
$destination= mysql_query($query_table2);
if ($source <= $destination){
echo 'aaa';
while($row_table1 = mysql_fetch_array($source)){
// var_dump ($row_table1);
// if statement
}
}
else {echo 'dalam else';}
}
?>