PHP PDO. error number '00000' when query is correct


This question already has an answer here:


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;

00000 means, it works fine. you should change your if to this: $sql3 === false.

The PDO::exec statement returns an integer to indicate the number of rows that were affected. So in your particular case, as the SomeKittens indicates, if 0 rows were affected, then your error code would be triggered.

However, if you are concerned as to whether your query worked, your better action may be to use PDO::query (in terms of your code ($returnObj = $connect->query($sql3) instead of PDO::exec.

The $returnObj can then be checked to see if there was an error in the SQL execution, and you can then troubleshoot your SQL query because it will tell you what the error was and where it was located.

Your best bet to do this would be:

//set PDO to throw an error so you can wrap the query in a try / catch block. 
$sql3 = "update news set date='$time' where id='2'";
try {
     $returnObj = $connect->query($sql3);
} catch (PDOException $e) {
    $error = $returnObj->errorInfo();
    die ("Error: (".$error[0].':'.$error[1].') '.$error[2]);

I just got similar situation in my php project - it occured that PDO Exception with error code '00000' took place when I tried to insert row with a field set to NULL while column defining the field in the database was of type ENUM('0', '1') and restriction NOT NULL. After modifying PHP script to place '0' instead of NULL, the error perished.

Further coding brought more light into the situation - I was performing more than one PDO statments within one DB transaction but checking errors (in Exception handling block) basing only on the first PDO statement executed while real error occured int the third PDO statement.

I had the same problem. It also tortured me a lot, but finally figured it out.

Suppose you have 7 columns in your table.

You are inserting data into 4 of them.

If for remaining 3 columns the default value is not set (say NULL for alpha-numeric columns, CURRENT_TIMESTAMP for date-time related columns etc.) then the above stated problem occurs.

If you are inserting data into all of those 7 columns or at least in those columns for which default value is not set, you wont get any error and data will get inserted.

Need Your Help

PyQt4 trouble creating a simple GUI application

python qt pyqt4

so I'm creating a simple windows application with Python and PyQt4. I've designed my UI the way I want it in QtCreator and I've created the necessary .py file from the .ui file. When I try to actua...

Stop a youtube video with jquery?

javascript jquery youtube

I have a jquery slider that I have built, basically just three pannels that slide by applying negative left CSS values. Works great, but I have a youtube video in one slide that wont stop when I sl...