SQLite: A Lightweight SQL Engine

PHP version 5 comes bundled with a SQL library that works with flat files, rather than with a database server. This is useful for writing PHP scripts in environments that don’t provide access to MySQL or to another third-party SQL server.

In this section we will discuss PHP’s SQLite functions. You shouldn’t need to do anything special to install SQLite, so let’s get straight to it with some code to open or create a new database. Because SQLite works with your file system, you need to work with a directory your script can write to:

$db = "data/testdb";
$dbres = sqlite_open($db, 0666, $error);
if ( ! is_resource( $dbres ) ) {
  die( "sqllite error: $error" );
}

The sqlite_open() function requires a path to a database ...

Get Sams Teach Yourself PHP in 24 Hours, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.