Fatal error: Call to undefined function sqlite3_open()


I’m trying to use SQLite3 (php.net/manual/en/book.sqlite3.php) and I enabled php_sqlite3 on my local machine (Win Vista) but I’m getting:

Fatal error: Call to undefined function sqlite3_open() in D:\wamp\www\somefolder\index.php on line 10

I’m using WAMP. Please help.

Have you restarted all services since enabling SQLite? The error you’re receiving indicates the extension is not enabled.

Yes, I did.

Does it appear in phpinfo() as one of the extensions?

(and why not just use the PDO_sqlite driver in any case)

I am still smarting over lost hours on this today, but if you were to make your database with some GUI tool, make sure it doesn’t make an sqlite2 database for you, or you will end up with less hair than me.

If it tells you it can convert it to sqlite3 then do not believe it.



Yes, it’s there in phpinfo. I believe PDO_sqlite is slower that’s why they are offering sqlite3 now. Am I wrong?

Well I am using PDO and it just picked up sqlite3, speed - cant say I have tested it - I seldom use sqlite at all.

If its appearing your phpinfo() then I cannot see why it is not working, sorry.

PHP is telling you the function does not exist. Are you forgetting to include something in your index.php file? Does SQLite have some .php files you need to include in the php you want to use its functions in?


Here’s what is showing in my phpinfo:


SQLite3 support	enabled
SQLite3 module version	0.7-dev
SQLite Library	3.6.15

Directive	Local Value	Master Value
sqlite3.extension_dir	no value	no value

And here is my code:


 * create a SQLite3 handle.
 * Note: in-memory database are created by the magic keyword ":memory:"

$db = sqlite3_open(":memory:");
if (!$db) die ("Could not create in-memory database..");

 * create a simple test and insert some values..

$ret = sqlite3_exec ($db, "CREATE TABLE test (id INTEGER, name TEXT, age INTEGER);");
if (!$ret) die (sqlite3_error($db));

sqlite3_exec($db, "INSERT INTO test (id,name,age) VALUES (1,'michael',32)");
sqlite3_exec($db, "INSERT INTO test (id,name,age) VALUES (2,'bob',27)");
sqlite3_exec($db, "INSERT INTO test (id,name,age) VALUES (3,'martin',12)");

 * Create a query

$query = sqlite3_query($db, "SELECT * FROM test ORDER BY age DESC");
if (!$query) die (sqlite3_error($db));

 * sqlite3_fetch_array() returns an associative array
 * for each row in the result set. Key indexes are
 * the columns names.

while ( ($row = sqlite3_fetch_array($query)))
        printf("%-20s %u\
", $row['name'], $row['age']);

 * do not forget to release all handles !

sqlite3_close ($db);


You should try the object-oriented approach with the SQLite3 extension: see the manual.

Whoops, thanks Salathe.