SQLite

Newest database extension with arguably the fastest interface between the database & PHP.
- Bundled with PHP 5 (including library)
- Fast and easy interface to 'flatfiles'
- Implements most of SQL92
- Supports both OO and procedural API
- No daemon required
- Enabled by default
- Can use PHP to extend SQL language

SQLite OO Interface

<?php
/* open connection to memory database */
$db = new SQLiteDatabase(":memory:");

/* execute a regular query */
$db->query("CREATE TABLE test(a,b)");
$db->query("INSERT INTO test VALUES('1','2')");

/* retrieve data using an unbuffered query */
$r $db->unbufferedQuery("SELECT * FROM test"SQLITE_ASSOC);
echo 
'<pre>';
/* use object iterators to retrieve the data, without any additional functions */
foreach ($r as $row) {
    
print_r($row);
}
echo 
'</pre>';
?>

Xuất ra

Array
(
    [a] => 1
    [b] => 2
)

SQLite Procedural Interface

<?php
function encode($str)
{
    return 
base64_encode(urlencode($str));
}

$db sqlite_open(":memory:"); // open database

/* create my functions */
sqlite_create_function($db'p_enc''encode'1);
sqlite_create_function($db'p_md5''md5'1);

sqlite_query($db"CREATE TABLE test(a,b)");
sqlite_query("INSERT INTO test VALUES(p_enc('1'),p_md5('2'))"$db);

echo 
'<pre>';
print_r(sqlite_array_query($db"SELECT * FROM test"SQLITE_NUM));
echo 
'</pre>';
?>

Xuất ra:

Array
(
    [0] => Array
        (
            [0] => MQ==
            [1] => c81e728d9d4c2f636f067f89cc14862c
        )
)