By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,890 Members | 1,048 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,890 IT Pros & Developers. It's quick & easy.

PDO SQllite error

P: 1
Hi,

I am trying to run this code on the Linux box...

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. // create a SQLite3 database file with PDO and return a database handle (Object Oriented)
  4. try{
  5.  
  6. $dbHandle = new PDO('sqlite:test.db');
  7.  
  8. }catch( PDOException $exception ){
  9.  
  10. die($exception->getMessage());
  11.  
  12. }
  13. // check if table/s needs to be created (PDO)
  14. $statement = $dbHandle->query('SELECT * FROM trace');
  15. $result = $statement->fetchAll();
  16.  
  17. if( sizeof($result) == 0 ){
  18.   echo 'No database table/s found.';
  19. }
  20.  
  21.  
  22. ?>
  23.  
I am getting the following error....

Fatal error: Call to a member function fetchAll() on a non-object in /usr/local/apache2/htdocs/zonebee/dev/PDORohit/pdosample2.php on line 15


Any thoughts?

Regards,
Rohit
Sep 26 '08 #1
Share this Question
Share on Google+
2 Replies


Markus
Expert 5K+
P: 6,050
Hey there, Rohitskapoor.

Welcome to the forums.

Please remember to post using [code] tags. [code] code goes here ... [/code]

Cheers.

Moderator
Sep 26 '08 #2

Atli
Expert 5K+
P: 5,058
Hi.

The PDO query function is obviously not returning the statement object as it should. Not sure why it would do that, the documentation doesn't mention what the function returns if the query should fail, so I would have assumed it simply returned and empty statement object.

In any case, try checking the return value of the query function first, like:
Expand|Select|Wrap|Line Numbers
  1. $stmt = $pdoHandle->query("...");
  2.  
  3. if($stmt) {
  4.   // Do your thing.
  5. }
  6. else {
  7.   echo "Query returned something weird: <br />";
  8.   var_dump($stmt);
  9. }
  10.  
Sep 26 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.