ericwright17 Posted December 27, 2009 Share Posted December 27, 2009 This is my entire document, when run, it give me the below error. What's up? <?php $mysql = new PDO('mysql:host=localhost;port=3306', 'root', ''); $list = $mysql->query('SELECT one,two,three FROM eric'); foreach ($list->fetchAll() as $row) { print "{$row['one']} goes with {$row['two']} and {$row['three']}"; } ?> Fatal error: Call to a member function fetchAll() on a non-object in C:\wamp\www\index.php on line 9 Again, its only my second day of learning this stuff, so please be nice! Link to comment https://forums.phpfreaks.com/topic/186400-day-two-of-learning-php-probably-an-easy-answer/ Share on other sites More sharing options...
cags Posted December 27, 2009 Share Posted December 27, 2009 I've never used PDO, but I'd imagine the query function is returning false because the query is failing. This would make the $list variable contain FALSE and thus obviously make $list->fetchAll() throw that error. I'm not sure how you would go about debugging when using PDO, but it's likely because either your connection is failing (seems unlikely else you'd probably get the same error for $mysql->query) or one, two, three or eric fields/table don't exists. Having said this Example #1 of the manual seems to suggest using a different method to what you have there. Link to comment https://forums.phpfreaks.com/topic/186400-day-two-of-learning-php-probably-an-easy-answer/#findComment-984342 Share on other sites More sharing options...
ericwright17 Posted December 27, 2009 Author Share Posted December 27, 2009 THANK YOU VERY MUCH! That fixed it! The query statement was failing, I was using my db name "eric" as opposed to my table's name. Link to comment https://forums.phpfreaks.com/topic/186400-day-two-of-learning-php-probably-an-easy-answer/#findComment-984348 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.