Php – Setting Up SQLite3 PDO Drivers in PHP

pdoPHPsqlite

I'm working my way 'slowly' through the php101 tutorials and have got to number 9, where I need SQLite.

I've got SQLite3 running and can access via the CLI, (see screenshot of a little test DB) but when I try the tutorial scripts in php101, I get a blank browser screen. I now know this is because SQLite3 uses PDO (php101 is based on SQLite v2).

Couldn't post and image so CLI says:

SQLite version 3.7.2

Enter ".help" for instructions

Enter SQL statements terminated with a ";"

sqlite> select * from books;

1|The Lord of the Rings|J.R. Tolkien

Etc Etc

Rather than go backwards, I'm trying to figure out how to enable the SQLite3 PDO driver (which I know is named sqlite) but those who have posted on stackoverflow to date, seems to have the SQLite driver installed and enable already, so driver config was not actually explained.

(sorry could post an image) but phpinfo for PDO says:

PDO

PDO support | enabled

PDO drivers |mysql

pdo_mysql

PDO Driver for MySQL |enabled

Client API version |5.1.49

I've checked on www.phpro.org/tutorials/Introduction-to-PHP-PDO but it is not explained there either.

My System is Linux Ubuntu 10.10

Apache – version 2.2.16

PHP version 5.3.3

SQLite 3.7.2

I'm trying to get this running on localhost as a learning aid initally.

Can someone explain how to install/configure the SQLite3 driver.

Best Answer

It's all easy when you know how, eventually found a post on www.news.php.net which provided a clue.

So for anyone else stuck on this, just open a terminal and enter:

sudo apt-get install php5-sqlite

note don't put a 3 and the end just leave it as sqlite

You will have to restart your machine, if you then check phpinfo you will find an entry for SQLite and the drivers enabled for sqlite2 and sqlite (note sqlite is the SQLite3 driver)

Hope this helps someone else in the future.