How to open a database, create a table if it doesn't exist and inserting initial value.
<?php
if ($db = new SQLiteDatabase('filename')) {
$q = @$db->query('SELECT requests FROM tablename WHERE id = 1');
if ($q === false) {
$db->queryExec('CREATE TABLE tablename (id int, requests int, PRIMARY KEY (id)); INSERT INTO tablename VALUES (1,1)');
$hits = 1;
} else {
$result = $q->fetchSingle();
$hits = $result+1;
}
$db->queryExec("UPDATE tablename SET requests = '$hits' WHERE id = 1");
} else {
die($err);
}
?>
Use this as boilerplate code for any new project using SQLite.