PDO error message?

JD Isaacks picture JD Isaacks · Oct 22, 2010 · Viewed 99.1k times · Source

Here is a snippet of my code:

$qry = '
    INSERT INTO non-existant-table (id, score) 
    SELECT id, 40 
    FROM another-non-existant-table
    WHERE description LIKE "%:search_string%"
    AND available = "yes"
    ON DUPLICATE KEY UPDATE score = score + 40
';
$sth = $this->pdo->prepare($qry);
$sth->execute($data);

print_r($this->pdo->errorInfo());

This should give me an error because the tables don't even exist. All I get however is this:

Array ( [0] => 00000 )

How can I get a better description of the error so I can debug the issue?

Answer

Alan Geleynse picture Alan Geleynse · Oct 22, 2010

Try this instead:

print_r($sth->errorInfo());

Add this before your prepare:

$this->pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );

This will change the PDO error reporting type and cause it to emit a warning whenever there is a PDO error. It should help you track it down, although your errorInfo should have bet set.