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 );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应