How to Enable SQLite3 for PHP

how to enable sqlite3 for php?

Edit: This answer is outdated, but can't be removed because it's accepted. Please see the solution from Stacey Richards for the correct answer.

 sudo apt-get install php5-cli php5-dev make
sudo apt-get install libsqlite3-0 libsqlite3-dev
sudo apt-get install php5-sqlite3
sudo apt-get remove php5-sqlite3
cd ~
wget http://pecl.php.net/get/sqlite3-0.6.tgz
tar -zxf sqlite3-0.6.tgz
cd sqlite3-0.6/
sudo phpize
sudo ./configure
sudo make
sudo make install
sudo apache2ctl restart

Ripped from the ubuntu form.

How to enable the PDO driver for sqlite3 in php?

I think that the PDO driver for sqlite3 is called 'sqlite', so you already have it installed. The sqlite2 driver is older.

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

In PHP 5.1, the SQLite extension also
provides a driver for SQLite 2
databases; while it is not technically
a part of the PDO_SQLITE driver, it
behaves similarly, so it is documented
alongside it. The SQLite 2 driver for
PDO is provided primarily to make it
easier to import legacy SQLite 2
database files into an application
that uses the faster, more efficient
SQLite 3 driver. As a result, the
SQLite 2 driver is not as feature-rich
as the SQLite 3 driver.

From http://php.net/manual/en/ref.pdo-sqlite.php

Enable sqlite3 FTS5 for PHP

I found that I have to generate header files before the last step

so the full steps looks like this:

$ yum install libsqlite3x-devel
$ wget -c http://www.sqlite.org/src/tarball/SQLite-trunk.tgz?uuid=trunk -O SQLite-trunk.tgz
$ tar -xzf SQLite-trunk.tgz
$ cd SQLite-trunk
$ ./configure
$ make fts5.c sqlite3.h sqlite3ext.h
$ gcc -g -fPIC -shared fts5.c -o fts5.so

Then I had to load the fts5.so as loadable extension for sqlite

1- Copy the fts5.so file to a new folder on server /sqlite_ext

$ mkdir /sqlite_ext
$ cp fts5.so /sqlite_ext

2- Edit sqlite3.extension_dir in php.ini to point to the same folder like this

sqlite3.extension_dir = "/sqlite_ext"

3- Then in my php file, load the extension :

$db->loadExtension('fts5.so');


Update :

It's better to update server's SQLite as a whole with --enable-fts5 option

$ wget -c https://www.sqlite.org/2019/sqlite-autoconf-3280000.tar.gz
$ tar -xzf sqlite-autoconf-3280000.tar.gz
$ cd sqlite-autoconf-3280000
$ ./configure --enable-fts5 --prefix=/usr --disable-static CFLAGS="-g -O2 -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_COLUMN_METADATA=1 -DSQLITE_ENABLE_UNLOCK_NOTIFY=1 -DSQLITE_SECURE_DELETE=1 -DSQLITE_SOUNDEX"
$ make
$ make install

Now the latest SQLite is installed for the server but not for PHP, let's do it for PHP

$ mv aclocal.m4 config.m4
$ phpize

Check for your SQLite version in server using $ sqlite3 --version and in PHP using phpinfo();

*notice: the link mentioned in the first step is for the latest sqlite-autoconf amalgamation at the time of this answer. there maybe a more recent version for you . check here

Sample Image



Related Topics



Leave a reply



Submit