我的PHP脚本中有一个函数可以从备份中恢复数据。一切都很好,工作得很好,直到突然它经过几个月的良好运作后停止工作。我正在使用OC 2.2.0,这个函数应该从oc_product_backup
表恢复产品及其数据。我print_r
每一步都会让我看到问题出在哪里,并意识到问题何在:
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');
}
答案 0 :(得分:0)
稍微查看一下代码后,似乎你准备好的语句绑定数据是在循环之外的,所以从技术上来说它永远不会编写任何数据。
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 = ?";
while ($row = $backup - > fetch_array(MYSQLI_ASSOC)) {
$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'];
$image = $row['image'];
$price_sync = $row['price_sync'];
$date_modified = $row['date_modified'];
$stmt = $mysqli - > prepare($updateproduct_sql);
$stmt - > bind_param('siss', $image, $modified_by, $date_modified, $product_id);
if (!$stmt - > execute())
return false;
$stmt2 = $mysqli - > prepare($updatedescription_sql);
$stmt2 - > bind_param('sssisi', $meta_description, $meta_keyword, $tag, $modified_by, $product_id, $language_id);
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');
}