Jump to content

Day Two of Learning PHP, Probably an easy answer


ericwright17

Recommended Posts

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!

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.