我有一個函數在我的PHP腳本中恢復備份數據。一切都很好,運轉良好,直到幾個月的工作良好後突然停止工作。我使用的是OC 2.2.0,此功能應該可以從oc_product_backup
表中恢復產品及其數據。我print_r
的每一步,這樣我就看到問題的所在,並意識到,當它到達:php腳本返回true突然停止返回值
return true;
它永遠不會發生。突然間有什麼可能是錯的,我該如何做這項工作?我從來沒有遇到過這樣的問題。我的功能看起來是這樣的:
function restoreBackup()
{
global $mysqli;
$i = 0;
$getpic = "SELECT * FROM oc_product_backup LIMIT 0, 100000";
$backup = $mysqli->query($getpic);
$mysqli->autocommit(FALSE);
$updateproduct_sql = "UPDATE oc_product SET image = ?, modified_by = ?, date_modified = ? WHERE product_id= ?";
$updatedescription_sql = "UPDATE oc_product_description SET meta_description = ?, meta_keyword = ?, tag = ?, modified_by = ? WHERE product_id = ? AND language_id = ?";
$stmt = $mysqli->prepare($updateproduct_sql);
$stmt->bind_param('siss', $image, $modified_by, $date_modified, $product_id);
//print_r ($updateproduct_sql);
$stmt2 = $mysqli->prepare($updatedescription_sql);
$stmt2->bind_param('sssisi', $meta_description, $meta_keyword, $tag, $modified_by, $product_id, $language_id);
//print_r($updatedescription_sql);
while($row = $backup->fetch_array(MYSQLI_ASSOC))
{
//$name = removeslashes($row['name']);
//$name = $row['name'];
//$description = removeslashes($row['description']);
//$description = $row['description'];
$meta_description = $row['meta_description'];
$meta_keyword = $row['meta_keyword'];
$tag = $row['tag'];
$product_id = $row['product_id'];
$modified_by = $row['modified_by'];
$language_id = $row['language_id'];
//if($row['language_id'] == 1)
//{
$image = $row['image'];
//$ean = $row['ean'];
//$name = $row['name'];
//$model = $row['model'];
//$status = $row['status'];
$price_sync = $row['price_sync'];
$date_modified = $row['date_modified'];
if(!$stmt->execute())
return false;
//}
if(!$stmt2->execute())
return false;
$i++;
if(($i % 500) === 0) $mysqli->commit();
}
$mysqli->commit();
$backup->close(); //the last line that gets executed
return true; //this never happens
writeToLog('- Backup restored');
}
也許你的腳本超時,因爲數據庫中的數據更多? (只是一個建議,不要釘死我) –
@SchalkKeun Thanx爲您的答覆 - 我的數據庫在整個時間內並沒有顯着增加,所以我不認爲這會是問題。但是,無論如何,這個建議都是對的。 – Nancy
你會得到一個空白頁面或網絡超時頁面?該腳本是在瀏覽器上執行還是作爲cron作業? –