【发布时间】:2014-09-09 09:04:17
【问题描述】:
我的 PDO SELECT 有问题,我尝试从数据库中获取数据,但是当函数获取对PDO->prepare 的请求冻结并且没有任何反应时,好像卡在它询问数据库的部分,导致第一个 ECHO在职的。我尝试使用(column= 'value') 更改SQL 语法,但结果仍然相同。此源代码是我在此应用程序中使用 OOP 的类中函数的一部分。请帮忙,谢谢。
在var_dump() 没有任何显示看起来像函数没有通过 trought PDO。
public function changePswd($old_pswd, $new_pswd, $user_id) {
echo $old_pswd . "<br/>" . $new_pswd . "<br/>" . $user_id;
try {
$stmt = $this->_db->prepare("SELECT * FROM zamestnanci WHERE id='" . $user_id . "'");
$stmt->execute();
if ($stmt->rowCount() > 0) {
$hash_pswd = $stmt->fetch(PDO::FETCH_ASSOC);
return $hash_pswd;
}
} catch (PDOException $e) {
throw new Exception('DATABASE ERROR: ' . $e->getMessage());
}
var_dump($hash_pswd);
【问题讨论】:
-
将您的
throw new Exception替换为echo。很可能您关闭了错误显示。 -
在 catch 子句中抛出异常会使 try/catch 基本上无用。