Migrating SQLite for PHP 5.2 to PHP 5.4 on Ubuntu

Written by Ben Wendt

PHP 5.4 discontinued support for SQLite 2 databases. Updating an old legacy PHP application with a SQLite database to a new server is not very difficult.

To start off, you will need the SQLite binaries so that you can convert the database between versions:

sudo apt-get install sqlite sqlite3

Now that you have the binaries installed, you can convert your version 2 SQLite database to version 3:

sqlite version2.db .dump | sqlite3 version3.db

Now you will need to update your PHP script with the following translations

Old command
New command
sqlite_escape_string()
SQLite3::escapeString()
sqlite_fetch_array($result)
$result->fetchArray()
sqlite_exec($handle, $query)
$handle->exec($query)
sqlite_query($handle, $query)
$handle->query($query)
$handle = sqlite_open($file)
$handle = new SQLite3($file)