Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么调试这个简单的PDO脚本时看不到错误?_Php_Mysql_Pdo_Nginx_Centos - Fatal编程技术网

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

Php 为什么调试这个简单的PDO脚本时看不到错误?,php,mysql,pdo,nginx,centos,Php,Mysql,Pdo,Nginx,Centos,我有一个简单的selectpdo脚本。当我从远程服务器发布到它时,我得到一个500错误。此错误未显示在我的日志中。我的错误日志设置为调试 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

我有一个简单的selectpdo脚本。当我从远程服务器发布到它时,我得到一个500错误。此错误未显示在我的日志中。我的错误日志设置为调试

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';
未显示异常错误消息

我刚得到一个“开始”的输出。很明显,脚本没有完成,但是为什么什么都不让我知道问题出在哪里呢?如果我的PDO语句有问题,不应该用$e-getMessage报告吗

调试这个时我遗漏了什么

您的web服务器的错误日志设置为调试。而显示的代码是PHP

因此,您必须让PHP记录错误。检查phpinfo中的值。日志错误必须设置为on,错误日志必须设置为null。这样,PHP将在错误日志中报告所有错误

另外,不要使用try/catch-echo之类的东西。切勿在实时服务器上输出错误消息

并将PDO设置为异常模式

$con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

啊,我明白了。我不认为nginx没有记录php错误。这是一个不输出错误的好提示,但我只是暂时这样做,因为我在日志中什么也看不到。不过,我已经在$con中设置了该属性。我已经在php.ini中更改了log_errors和error_log,现在已重新启动。这帮了大忙。我需要再读一读这本小册子——干杯。