Search
Syndication
Sponsors

Create a sqlite database

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 4.00 out of 5)


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

Related posts:

  1. Build Your Own Database Driven Web Site Using PHP & MySQL (Paperback) “Build Your own Database Driven Web Site Using PHP...
  2. Ajax and PHP Stock Quote example This is  a new source code section so we thought...
  3. Get Dow Jones stock market data This example retrieves the latest Dow Jones data from Yahoo...
  4. PHP and MySQL for Dummies (Paperback) Build an online catalog and a members–only site Everything...
  5. Learning PHP, MySQL, and JavaScript: A Step-by-Step Guide to Creating Dynamic Websites (Paperback) Learn how to create responsive, data-driven websites with PHP,...

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



Tags: , , , , ,

Leave a Reply