Create a sqlite database

This example creates a sample sqlite database and populates it with some data

<?php
//Open/Create sqlite db
if (!($db = sqlite_open(‘sample.db’)))
{
    die(sqlite_error_string(sqlite_last_error($db)));
}

//create a table and populate with some data
$sql = ”
create table sample (
    id   integer  primary key,
 cat   text not null,
    title text     not null
);

insert into sample (cat, title) values (‘programming’,’getphp’);
insert into sample (cat, title) values (‘sport’, ‘golf site’);
insert into sample (cat, title) values (‘programming’,’java site’);
insert into sample (cat, title) values (‘search’,’google’);
“;

//handle failure or success
if (!(sqlite_exec($db, $sql)))
{
    die(‘SQL ERROR: ‘ . sqlite_error_string(sqlite_last_error($db)));
}
else
{
    echo ‘Database and table created!’;
}

//tidy things up
sqlite_close($db);
?>

LEAVE A REPLY

Please enter your comment!
Please enter your name here

*