Axeia Posted June 24, 2011 Share Posted June 24, 2011 Hello, I'm using PDO to connect to a SQLite database. Locally under wamp everything runs fine, on my testserver running openSUSE 11.4 / apache / php5 everything is running fine as well. On my host however it doesn't seem to work at all, and I'm not getting any useful information from PHP either. I'm using the code below in the __construct of my database class. $dbLoc = dirname(dirname(dirname(__FILE__))).DIRECTORY_SEPARATOR.'external_access_denied'.DIRECTORY_SEPARATOR.'ic.db3'; try { $this->db = new PDO('sqlite:'.$dbLoc); echo '<pre>!'.print_r($this->db,true).'</pre>'; $prep = $this->db->query('SELECT name FROM sqlite_master'); echo '<pre>!'.print_r($prep).'</pre>'; echo $prep instanceof PDOStatement.'<br/>'; echo '<pre>!'.print_r($prep->fetchAll()).'</pre>'; } catch( PDOException $e ) { echo 'a----'; Util::logError(__FILE__, __LINE__, $e->getMessage()); } catch( Exception $e ) { echo 'b----'; Util::logError(__FILE__, __LINE__, $e->getMessage()); } The output I get on my host: !PDO Object ( ) !1 Fatal error: Call to a member function fetchAll() on a non-object in*snip*ncludes/classes/Database.class.php on line 42 line 42 is "echo '<pre>!'.print_r($prep->fetchAll()).'</pre>';" from the code example. Locally I get !PDO Object ( ) PDOStatement Object ( [queryString] => SELECT name FROM sqlite_master ) !1 1 followed by a long array with the query results. -- So what is going wrong? I'm not getting PDOStatement object on the host even the PDO object is there. instanceof seems to think it's a PDOStatement, but print_r thinks different. If anyone could shine a light on this I'd be impressed.. rather flabbergasted myself. Quote Link to comment https://forums.phpfreaks.com/topic/240329-pdostatement-problem-that-doesnt-seem-to-throw-an-error/ Share on other sites More sharing options...
Axeia Posted June 25, 2011 Author Share Posted June 25, 2011 Thinking it might be a problem due to different versions of the SQLite library I tried deleting the database both on the host and locally. Similiar result, locally I get a PDOStatement with the original query but on the host this does not happen although the database is created just fine. Quote Link to comment https://forums.phpfreaks.com/topic/240329-pdostatement-problem-that-doesnt-seem-to-throw-an-error/#findComment-1234654 Share on other sites More sharing options...
Axeia Posted June 26, 2011 Author Share Posted June 26, 2011 After wasting hours on this I found the cause. The SQLite database I'm using makes use of foreign keys. The host is running version 3.3.7 of SQLite which does not support foreign keys and isn't compatible with databases containing these it seems. Found out by recreating the entire database using PDO statements, downloading the database and then finding out tables with foreign keys aren't created. Quote Link to comment https://forums.phpfreaks.com/topic/240329-pdostatement-problem-that-doesnt-seem-to-throw-an-error/#findComment-1234958 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.