Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PDO: Call to a member function errorInfo()

Tags:

php

mysql

pdo

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?

like image 241
user2420824 Avatar asked Jul 18 '26 12:07

user2420824


1 Answers

See https://www.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.

like image 57
bwoebi Avatar answered Jul 20 '26 03:07

bwoebi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!