Using SQLite in PHP 5

Album Cover: Wincing the Night Away

"It's like I'm perched on the handlebars of a blind man's bike."
The Shins / Spilt Needles

Posted on August 02, 2004 12:37 PM in Web Development
Warning: This blog entry was written two or more years ago. Therefore, it may contain broken links, out-dated or misleading content, or information that is just plain wrong. Please read on with caution.

I wanted to give PHP 5's built-in SQLite support a whirl today, so I spent about 10 minutes writing up the following script:

* SQLite Testing *
* By Bernie Zimmermann *

/* open new database */
$connect = sqlite_open("badmusic");

/* build an SQL statement */
$sql = "create table songs(title char)";

/* run the query */
sqlite_query($sql, $connect);

/* build an SQL statement */
$sql = "insert into songs values ('I Want It That Way')";

/* run the query */
sqlite_query($sql, $connect);

/* build an SQL statement */
$sql = "select title from songs";

/* run the query */
$res = sqlite_single_query($sql, $connect);

/* print the result */

The beautiful thing is, it worked. It just worked. You don't have to spend time setting up databases and granting user permissions like you would in MySQL. You just write the script and run it.

The above script produces the following output, thanks to the sqlite_single_query() function, which looks like a nifty little function:

I Want It That Way

If you have access to PHP 5, you should definitely give the new SQLite functionality a try.


Arcanius on August 02, 2004 at 3:49 PM:

SQLite is the one thing in PHP 5 that I'm most excited about, precisely for the reason you just described: zero setup databases. A corallary to that is extremely portable databases, since the database file resides with the rest of the website. I'm itching to install PHP5 on, because I care so much more about cutting-edgedness than security. :-)


matsolof on September 17, 2008 at 10:26 AM:

The script didn't work when I tried it (beside producing the warnings "unable to open database" and "expects parameter 1 to be resource").

Any suggestions? I have no clue when it comes to data bases.


Mediafre on July 07, 2011 at 5:10 AM:

Is php 5.1 supports Sqlite?


8 ball pool cheats on January 31, 2018 at 12:30 AM:

Do me one favor try 8 ball pool coins hack for get unlimited ball pool coins.


Post Comments

If you feel like commenting on the above item, use the form below. Your email address will be used for personal contact reasons only, and will not be shown on this website.


Email Address:



Check this box if you hate spam.