PHP and SQLite

From Techotopia
Revision as of 16:45, 7 June 2007 by Neil (Talk | contribs) (New page: SQLite is an embedded database that is bundled with PHP starting with PHP 5 and implements a large subset of the SQL 92 standard. SQLite has a number of advantages such as speed, simple s...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

SQLite is an embedded database that is bundled with PHP starting with PHP 5 and implements a large subset of the SQL 92 standard.

SQLite has a number of advantages such as speed, simple storage (avoiding the need for complex database administration) and interoperability with other databases such as MySQL and PostgreSQL.

Creating an SQLite Datbase with PHP

An SQLite datbase can be PHP sqlite_open() function. This function accepts one mandatory and two optional arguments. The first argument is the database name (which, by convension, is given a .sqlite file extension). The second argument specifies option UnIX pfile permission settings. The final argument represnets an error message to diaplay if the file cannot be opened.

The sqlite_open() returns a datbase handle on success, or a boolean false value on failure. A memory resiodent database can be created by passing in the string :memory as the datbase file name argument.

SQLite databases are closed using the sqlite_close() function.

The following example opens a database called phptest.sqlite:

<?php
        $dbhandle = sqlite_open('phptest.sqlite');

        if ($dbhandle == false)
        {
                echo 'Unable to open database';
        } else {
                echo 'Database created.';
        }
?>