Categories

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);
?>

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>