0
我是新來的PDO,並試圖瞭解它是如何工作的。以下是從數據庫中刪除用戶的片段:如何用PDO縮短mySQL查詢?
$stmt = $db->prepare("-- 02 account_delete.php
DELETE FROM " . TABLE_ADDRESS_BOOK . " WHERE customers_id = :id");
$stmt->bindParam(':id', $_SESSION['customer_id'], PDO::PARAM_INT);
$stmt->execute();
$stmt = $db->prepare("-- 03 account_delete.php
DELETE FROM " . TABLE_CUSTOMERS . " WHERE customers_id = :id");
$stmt->bindParam(':id', $_SESSION['customer_id'], PDO::PARAM_INT);
$stmt->execute();
$stmt = $db->prepare("-- 04 account_delete.php
DELETE FROM " . TABLE_CUSTOMERS_INFO . " WHERE customers_info_id = :id
");
$stmt->bindParam(':id', $_SESSION['customer_id'], PDO::PARAM_INT);
$stmt->execute();
如何縮短例如將它組合成一個數組或其他東西。我也想知道爲什麼我必須重複:
$stmt->bindParam(':id', $_SESSION['customer_id'], PDO::PARAM_INT);
否則它不起作用。
有時我看不到樹木。我把這三個查詢放入一個數組中,並使用foreach循環。 – user1286819 2013-03-02 11:37:52