为什么我看不到调试这个简单的PDO脚本的错误?

时间:2013-12-21 07:31:35

标签: php mysql pdo nginx centos

我有一个简单的选择PDO脚本。当我从远程服务器发布它时,我收到500错误。此错误未显示在我的日志中。我的error_log设置为debug。

header("access-control-allow-origin: *");

// includes connect to db file here, $con is declared here - 
// this is included in other working scripts currently.

echo 'start';

try {
    $stmt = $con->prepare('SELECT * FROM users WHERE userEmail=:email ');
    $stmt = $con->bindValue(':email','myemail@example.com');
    $stmt->execute();
 } 
 catch (PDOException $e) {
    echo $e->getMessage();
 }


echo 'finish';

显示无异常错误消息。

我只得到'start'的输出。显然脚本没有完成,但为什么没有让我知道问题是什么?如果我的PDO语句出现问题,是否应该使用$ e-getMessage()报告?

调试此内容我缺少什么?

1 个答案:

答案 0 :(得分:1)

这是你的 web-server的,error_log设置为debug。虽然显示的代码是PHP。

因此,您必须让PHP记录错误。检查phpinfo()中的值。 log_errors必须设置为onerror_lognull。这样PHP将报告error_log

中的所有错误

另外,摆脱try / catch echo的东西。切勿在实时服务器上输出错误消息。

并在异常模式下设置PDO。

$con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
相关问题