topical media & game development

talk show tell print

server-php-sqlite-demo-connect.php / php



    <?php
  // create new database (procedural interface)
  db = sqlite_open("server-php-sqlite-demo.db");
  
  // uncomment next line if you still need to create table foo
  // sqlite_query(db , "CREATE TABLE foo (id INTEGER PRIMARY KEY, name CHAR(255))");
  
  // insert sample data
  sqlite_query(db, "INSERT INTO foo (name) VALUES ('Ilia')");
  sqlite_query(db, "INSERT INTO foo (name) VALUES ('Ilia2')");
  sqlite_query(db, "INSERT INTO foo (name) VALUES ('Ilia3')");
  
  // execute query
  result = sqlite_query(db, "SELECT * FROM foo");
  // iterate through the retrieved rows
  while (row = sqlite_fetch_array(result)) {
      print_r(row);
      /* each result looks something like this
      Array
      (
          [0] => 1
          [id] => 1
          [1] => Ilia
          [name] => Ilia
      )
  */
  }
  
  // close database connection
  sqlite_close(db);
  
  ?> 
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.