PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Introducere> <pg_version
Last updated: Fri, 01 Aug 2008

view this page in

SQLite



add a note add a note User Contributed Notes
SQLite
saivert at saivert dot com
30-Apr-2008 09:02
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.

Introducere> <pg_version
Last updated: Fri, 01 Aug 2008
 
 
show source | credits | sitemap | contact | advertising | mirror sites