3

I read this tutorial about PDO. I had an error and tried the errorInfo() function. However, I get this error when trying to use errorInfo():

Fatal error: Call to a member function errorInfo() on a non-object in C:\Users\Nico\Dropbox\PHP\Vagex Clone\Website\pdo\select.php on line 8

I used this code as it's in the tutorial:

$query = $db->query('SELECT * FROM notexistingtable'); //that was the error I had 

if (!$query) {
var_dump($query->errorInfo());
} 

So - if I have an error like this, how do I correctly use the errorInfo() function?

user2420824
  • 35
  • 1
  • 5
  • 1
    You don't need errorInfo() function. [PDO query fails but I can't see any errors. How to get an error message from PDO?](http://stackoverflow.com/a/15990858/285587) – Your Common Sense Jun 09 '13 at 16:01

1 Answers1

4

See http://lu1.php.net/manual/en/pdo.errorinfo.php: errorInfo is a method of PDO (the instance is here $db) and not of false which is returned by the failing query.

So use $db->errorInfo() for getting the failure info.

bwoebi
  • 23,637
  • 5
  • 58
  • 79