我是 PDO 的新手,并试图了解它是如何工作的。这是从数据库中删除用户的片段:
$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);
否则它不起作用。