我想對PHP PDO
類的工作,但我有一些麻煩,找到處理錯誤的正確方法,我已經寫了這個代碼:如何處理PDO異常
<?php
// $connection alreay created on a class which works with similar UPDATE statements
// I've simply added here trim() and PDO::PARAM... data type
$id = 33;
$name = "Mario Bros.";
$url = "http://nintendo.com";
$country = "jp";
try {
$sql = "UPDATE table_users SET name = :name, url = :url, country = :country WHERE user_id = :user_id";
$statement = $connection->prepare ($sql);
$statement->bindParam (':user_id', trim($id), PDO::PARAM_INT);
$statement->bindParam (':name', trim($name), PDO::PARAM_STR);
$statement->bindParam (':url', trim($url), PDO::PARAM_STR);
$statement->bindParam (':country', trim($country), PDO::PARAM_STR, 2);
$status = $statement->execute();
} catch (PDOException $e) {
print $e->getMessage();
}
print $status; // it returns a null value, and no errors are reported
?>
的這部分代碼不報告錯誤,但它根本不起作用,在底部var $status
,返回一個空值。
有人能幫我找到我錯在哪裏嗎?
簡單,快捷!謝謝 – vitto 2010-01-20 20:03:43
@Matchu:這是默認行爲?從何時起?! – 2010-01-20 20:09:17
自從我上個月前建立了一個數據庫類以來。至少在我的環境中,默認模式是默認模式。 – Matchu 2010-01-20 20:13:44