我正在尝试在数据库上为本地托管的示例购物网站实现表锁。
以下是我的index.php的示例:
case "add":
if(!empty($_POST["quantity"])) {
if(!isset($timestamp)){
$timestamp = time();
$lock = $db_handle->runQuery("LOCK TABLE orders_f write,prod_f read");
}
$productByCode = $db_handle->runQuery("SELECT * FROM prod_f WHERE code='" . $_GET["code"] . "'");
$itemArray = array($productByCode[0]["code"]=>array('name'=>$productByCode[0]["name"],'code'=>$productByCode[0]["code"],'quantity'=>$_POST["quantity"],'price'=>$productByCode[0]["price"]));
if(!empty($_SESSION["cart_item"])) {
if(in_array($productByCode[0]["code"],array_keys($_SESSION["cart_item"]))) {
foreach($_SESSION["cart_item"] as $k => $v) {
if($productByCode[0]["code"] == $k) {
if(empty($_SESSION["cart_item"][$k]["quantity"])) {
$_SESSION["cart_item"][$k]["quantity"] = 0;
}
$_SESSION["cart_item"][$k]["quantity"] += $_POST["quantity"];
}
}
} else {
$_SESSION["cart_item"] = array_merge($_SESSION["cart_item"],$itemArray);
}
} else {
$_SESSION["cart_item"] = $itemArray;
}
已强制执行表锁定的位置。尝试添加到购物车中时,出现以下错误,这是上述case语句的来源:
警告:mysqli_fetch_assoc()期望参数1为mysqli_result,第24行的path \ dbcontroller.php中给出的布尔值 这是我的dbcontroller.php的代码段:
function runQuery($query) {
$result = mysqli_query($this->conn,$query);
while($row=mysqli_fetch_assoc($result)) {
$resultset[] = $row;
}
if(!empty($resultset))
return $resultset;
else
return false;
}
我整夜都在Youtube和Stackoverflow上进行搜索,但是所有选项似乎都无效。它位于Apache
计算机上使用Wamp的64 bit Windows 10
服务器上。请提出任何建议。