Jump to content

PDOStatement problem that doesn't seem to throw an error..


Axeia

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.