问题
I'm trying to update a single element in one of my tables using a PDO prepared statement, and for some reason it's not working. I'm using try-and-catch and I'm receiving no errors from the system. I've also echoed both of my bound parameters, and they are both registering in the system, so I don't know why it's not going through. I've used a query very similar to this in another script and everything was fine.
if($_POST['check_request'] == "Yes"){
$check_amnt = $_POST['check_amnt'];
try {
$STH = $DBH->prepare('UPDATE accounts SET check = :check_amnt WHERE accnt = :user');
$STH->bindParam(':check_amnt', $check_amnt);
$STH->bindParam(':user', $ulog);
$STH->execute();
}
catch(PDOException $e) {
echo "Check Input Error: " .$e->getMessage(). "</br>";
}
}
回答1:
Did you set the exception mode for PDO with:
$DBH->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
Update:
check is mysql reserved words, you need to escape it.
$STH = $DBH->prepare('UPDATE accounts SET `check` = :check_amnt WHERE accnt = :user');
来源:https://stackoverflow.com/questions/12190452/php-pdo-not-updating-table-and-producing-no-errors