我正在使用Opencart v2.2.0,我的php脚本出现问题。有问题的一行是:
$stmt2->bind_param('sssssisi', $name, $description, $meta_description, $meta_keyword, $tag, $modified_by, $product_id, $language_id);
包括上述行的整个功能如下:
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 = ?, ean = ?, model = ?, status = ?, price_sync = ?, modified_by = ?, date_modified = ? WHERE product_id= ?";
$updatedescription_sql = "UPDATE oc_product_description SET name = ?, description = ?, meta_description = ?, meta_keyword = ?, tag = ?, modified_by = ? WHERE product_id = ? AND language_id = ?";
$stmt = $mysqli->prepare($updateproduct_sql);
$stmt->bind_param('sssiiiss', $image, $ean, $model, $status, $price_sync, $modified_by, $date_modified, $product_id);
$stmt2 = $mysqli->prepare($updatedescription_sql);
$stmt2->bind_param('sssssisi', $name, $description, $meta_description, $meta_keyword, $tag, $modified_by, $product_id, $language_id);
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'] == 4)
{
$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();
return true;
}
function removeslashes($string)
{
$string=implode("",explode("\\",$string));
return stripslashes(trim($string));
}
我得到的错误是
致命错误:在
中的布尔值上调用成员函数bind_param()
有什么建议吗?我不知道我做错了什么。提前谢谢大家。
答案 0 :(得分:2)
prepare()方法可以返回false,你应该检查它。至于为什么它返回false,表名或列名(在SELECT,UPDATE或WHERE子句中)可能不正确?
另外,请考虑使用$ query-> error_list之类的内容来检查解析SQL时发生的错误。 (我偶尔会回复实际的SQL语句字符串并粘贴到phpMyAdmin进行测试,但肯定会有一些失败。)