drhe80011 2013-12-21 07:31
浏览 47
已采纳

为什么我看不到调试这个简单的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 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 );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?