willdanceforfun
willdanceforfun

Reputation: 11240

Why can't I see an error to debug this simple PDO script?

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','[email protected]');
    $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?

Upvotes: 0

Views: 63

Answers (1)

Your Common Sense
Your Common Sense

Reputation: 157910

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 );

Upvotes: 1

Related Questions