Ubuntu – SQLite stopped working after upgrade

12.04PHPsqlite

As many of you did, I upgraded from Lucid to Precise this week and almost everything seems to work find.

everything except… SQLite, which was working well before but not anymore.

I checked everything: phpinfo(), php.ini, sqlite3.ini.

The sqlite command works fine, but when I try to use PHP… *PLOP*, nothing works.

I get the message

Fatal error: Class 'SQLiteDatabase' not found in /var/www/test/sqlite/index.php on line 4

Line 4 being

$db = new SQLiteDatabase('test.sqlite', 0666);

Any hint?


edit

You can see my phpinfo() here: http://pastebin.com/jQ7Bz0GN

The apache log is

 * Restarting web server apache2
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName

Best Answer

Extensions

According to Vendor Specific Database Extensions page on the PHP site, there are two SQLite extensions:

SQLite3 extension is a newer replacement of SQLite, which soon will become obsolete:

The SQLite extension is enabled by default as of PHP 5.0.
Beginning with PHP 5.4, the SQLite extension is available only via PECL.

Ubuntu 10.04 vs 12.04

Now, some practicalities. Let's have a look at default web server configuration that was installed using:

sudo apt-get install apache2 php5 php5-sqlite

Ubuntu 10.04:

# php --ri sqlite

SQLite

SQLite support => enabled
PECL Module version => 2.0-dev
SQLite Library => 2.8.17
SQLite Encoding => UTF-8

# php --ri sqlite3

sqlite3

SQLite3 support => enabled
SQLite3 module version => 0.7-dev
SQLite Library => 3.6.22

Ubuntu 12.04:

# php --ri sqlite

Extension 'sqlite' not present.

# php --ri sqlite3

sqlite3

SQLite3 support => enabled
SQLite3 module version => 0.7-dev
SQLite Library => 3.7.9

So, Ubuntu 12.04 default PHP installation (as of writing this - version 5.3.10) already does not have sqlite extension as built in. The output above states that only sqlite3 extension is present, which came from php5-sqlite package.

Solution

Pick your evil:

  1. Right approach in long term would be to adapt the code to get it working under SQLite3. The changes would be minor, but this might involve some unwanted copy-paste-style work on a big amount of files. If this is the case, and right is not a right word here, solution 2 is for you.
  2. Install obsolete extension from PECL.
Related Question