PHP PDO. error number '00000' when query is correct [duplicate] PHP PDO. error number '00000' when query is correct [duplicate] database database

PHP PDO. error number '00000' when query is correct [duplicate]


The PDO error code 00000 means that everything works fine. The reason you're hitting the error-checking code is that $sql3 is returning 0 (no rows were effected) and PHP evaluates that to false. Try explicitly checking for a return false;

if($sql3 === false)


If exec does not update any row, it will return 0. that makes if(!$sql3) evaluate to false, you should do this instead :

if($sql3 === false){}


In my experience badly formed queries (syntax errors) and failed queries (for example an INSERT that didn't insert anything) also may WRONGLY return error code 00000. You should go ahead and try to run the complete query on your SQL console and see why it failed. I really don't know why the proper error message isn't returned though. Here's a snippet of the code we use

    $r = $pdo->prepare($sql);    if (!$r->execute($input_parameters)) { # query failed        if ($bLogFailures) {            error_log('query failed: ERROR['.$pdo->errorCode().':'.print_r($pdo->errorInfo(), true).'] QUERY['.$sql.']');        }        return false;    }