SQLite PHP




With the help of Zend’s developer zone, I made my first SQLite script:


#!/usr/local/bin/php
<?php



if(!is_file("db.sqlite")) { 
    $db = new SQLiteDatabase("db.sqlite");
    $db = sqlite_open("db.sqlite");
sqlite_query($db , "CREATE TABLE foo (id INTEGER PRIMARY KEY, name CHAR(255))");
sqlite_query($db, "INSERT INTO foo (name) VALUES ('Ilia')");
sqlite_query($db, "INSERT INTO foo (name) VALUES ('Ilia2')");
sqlite_query($db, "INSERT INTO foo (name) VALUES ('Ilia3')");
exit;
}


$db = sqlite_open("db.sqlite");

$result = sqlite_query($db, "SELECT * FROM foo");
// iterate through the retrieved rows
while ($row = sqlite_fetch_array($result)) {
    echo "<pre>";
    print_r($row);
    /* each result looks something like this
    Array
    (
        [0] => 1
        [id] => 1
        [1] => Ilia
        [name] => Ilia
    )
*/
}
?>

So far, I’m pretty excited about using sqlite. I was concerned about the foreign keys, but I just found this. You can create the equivalent of foreign key constraints with triggers, and triggers are supported by SQLite, Postgres, and MySQL!

Following on that minor progress, I added basic SQLite support to the pdo datasource in nexista.

0 Responses to “SQLite PHP”


  1. No Comments

Leave a Reply