0
if($_REQUEST['action'] == 'addToCart' && !empty($_REQUEST['id'])){
$productID = $_REQUEST['id'];
// get product details
$query = $db->query("SELECT * FROM products WHERE id = ".$productID);
$row = $query->fetch_assoc();
$itemData = array(
'id' => $row['id'],
'name' => $row['name'],
'price' => $row['price'],
'qty' => 1
);
$insertItem = $cart->insert($itemData);
$redirectLoc = $insertItem?'viewCart.php':'index.php';
header("Location: ".$redirectLoc);
}
我試圖將此代碼轉換爲PDO stmt。請幫助我,我是新來的。如何將mysqli代碼轉換爲PDO stmt?
'$ db'是'pdo'連接還是'mysqli'?到目前爲止你做了什麼? 'prepare(「SELECT * FROM products WHERE id =?」'''execute(array($ productID))' – chris85
您可能想向我們展示您的數據庫類,以便我們可以看到它在做什麼 – icecub