drhe80011
2013-12-21 07:31 阅读 46
已采纳

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

I have a simple select PDO script. When I post to it from a remote server, I get a 500 error. This error isn't showing up in my logs. My error_log is set to 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';

No exception error message is shown.

I just get an output of 'start'. Clearly the script isn't completing, but why is nothing letting me know what the problem is? If there is a problem with my PDO statement, shouldn't this be reported with $e-getMessage() ?

What am I missing to debug this?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    dss524049 dss524049 2013-12-21 07:55

    It's your web-server's error_log is set to debug. While the code shown is PHP.

    So, you have to make your PHP to log errors. Check values from phpinfo(). log_errors have to be set to on and error_log to null. This way PHP will report all the errors in the error_log

    Also, get rid of try/catch echo stuff. NEVER output an error message on a live server.

    And set PDO in exception mode.

    $con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
    
    点赞 评论 复制链接分享

相关推荐