Monday, February 08, 2010

Getting SQLite to work in PHP (PHP5) on Windows Server

I just wanted to use the existing code....

But it seems PHP5 underwent a big change in "PDO" for SQLite.

I went around the houses looking at errors like "Class 'SQLite3' not found php" and " Fatal errorCall to undefined function sqlite_open()"

But... finally I found: http://djhweb.co.uk/sqlite1.htm

So I had to change the code:

$db = sqlite_open('filename',0666)

to 

$db = new PDO('filename');

Then:

$res = sqlite_query($db, $query, SQLITE_ASSOC);

to

$res = $db->query($query);

And:

$row=sqlite_fetch_array($res);

to

$row=$res->fetch(PDO::FETCH_ASSOC);

I might have got some of this wrong... but hopefully not!

If you hit "SQLSTATE[HY000] [14] unable to open database file" then that means you need to open up read/write permissions on the database directory.

2 comments: