Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Up SQLite3 PDO Drivers in PHP

Tags:

php

sqlite

pdo

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.

like image 947
wayneLN Avatar asked Jan 05 '11 20:01

wayneLN


People also ask

Does PDO work with SQLite?

PDO_SQLITE is a driver that implements the PHP Data Objects (PDO) interface to enable access to SQLite 3 databases.

Does PHP support SQLite3?

PHP provides two SQLite extensions by default since version 5.0. The latest SQLite extension is known as sqlite3 extension that is included in PHP 5.3+.

How do I install PDO drivers?

Pdo ( Portable Data Object ) needs to be installed if it is not done before. For windows platform go to control panel > Add remove program ( or Programs and features ) > Select your PHP installation and click Change. If you are installing PHP fresh then in the setup wizard you can select PDO from Extensions link.


1 Answers

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.

like image 62
wayneLN Avatar answered Nov 11 '22 23:11

wayneLN