Why class 'SQLiteDatabase' is not found in /var/www/*.php?

Class SQLiteDatabase is an object from sqlite library, which support was dropped in PHP 5.4, but on various systems and configuration could be disabled in an earlier releases, as this library was long time marked as going to be deprecated.

Library php_sqlite.dll (Windows) or php_sqlite.so (Linux) is no longer supported in newer versions of PHP and was replaced with php_sqlite3.dll or php_sqlite3.so respectively.

You can:

  1. Try to find php_sqlite.dll (php_sqlite.so) somewhere in the Internet. Links like this or this may be helpful for you. However, you'll have to carefully match old SQLite library file to your PHP's platform (x64 or x86), build engine (VC6, VC9 or VC11), version (5.x) and type (TS for thread safe or NTS for non-thread safe). This might be a hard task.

  2. Leave php_sqlite.dll (SQLiteDatabase) behind and ship toward new php_sqlite3.dll (SQLite3 object). You have to first use a tool like SQLite Studio to convert your database file from 2.1 to 3.0 (size can be lowered by even a half) and then carefully compare SQLite and SQLite3 PHP manual pages to change necessary objects and functions call.

If option two, note that this shouldn't be a hard work, as changes aren't that big. For example, what I've learned so far:

  • SQLiteDatabase -> SQLite3,
  • SQLiteDatabase::unbufferedQuery -> SQLite3::query,
  • SQLiteResult::fetchAll(SQLITE_*) -> SQLite3Result::fetchArray(SQLITE3_*) etc.

As for fetching, in old SQLite we had:

$rowsIMEI = $db->unbufferedQuery($imeiSQL)->fetchAll(SQLITE_ASSOC);

foreach($rowsIMEI as $r)
{
    ...
}

While, in new SQLite3 we should:

$rowsIMEI = $db->query($imeiSQL);

while($r = $rowsIMEI->fetchArray(SQLITE3_ASSOC))
{
    ...
}

Other changes requires similar amount of work, so this shouldn't be a life-time process.

I, of course, strongly advice anyone to go forward and choose second option. Progress is in most cases the better one of two available options.


There's quite a few reports of the same issue out on Google but no definitive solution.

Double-check your SQLlite extension is enabled in PHP, and you should be able to use the sqlite_* family of functions (such as sqlite_open) instead of the OOP approach, not ideal I know.

Also just check that your PECL module for sqlite is >= 1.0.0.


I had the same problem.

If you upgraded your php version, some of old configuration files may be referencing a non existent file.

Look at the ".ini" files at "conf.d" directory. In my case the path of my "conf.d" directory is "/etc/php5/conf.d" in a Debian system.

Talking specifically about "SQLiteDatabase" class, my problem was the "sqlite.ini" file pointing to "sqlite.so" which does not exist.

After deleting the "sqlite.ini" file, make sure that there are a ini file pointing to a valid sqlite extension (in this case the "sqlite3.ini" pointing to "sqlite3.so") and restart the apache all worked fine for me.

Hope it helps.

Tags:

Php

Sqlite