<HTML><BODY>

This sample PHP script shows how to use a SQLite database. 

This script should be run from a cd rom containing the MicroWeb software. 

This will copy a database from the cd to a temp directory on the users PC in order to perfrom
writeable operations.


<?php 
//dynamically load the pd library, required by sqlite
if (!extension_loaded('pdo')) { dl('php_pdo.dll'); }
//dynamically load the php_sqlite library
if (!extension_loaded('sqlite')) { dl('php_sqlite.dll'); }

// include the library
include_once 'php\SPSQLiteClass-0.6\SPSQLite.class.php'; 

$dbdir = str_replace('\\', '/', $_ENV[TEMP]) . "/dbdir";
$dbfile = $dbdir . "/sqlitedb.db";
$dbfile_cd = "../dbdir/sqlitedb.db";


//copy database from cd to local drive, if local copy does not already exist
if (!is_dir($dbdir))
{
    mkdir($dbdir) or die ("Could not make directory");
    copy($dbfile_cd, $dbfile); 
}

$handle = fopen($dbfile, "a+");
$sqlite =& new SPSQLite($dbfile); 

//$queries = array( 
//            "INSERT INTO test (name, quantity, price) VALUES('toro', 10, 500.00);", 
//            "INSERT INTO test (name, quantity, price) VALUES('gallo', 5, 200.00);", 
//            "INSERT INTO test (name, quantity, price) VALUES('rana', 20, 100.00);", 
//            "INSERT INTO test (name, quantity, price) VALUES('cane', 3, 500.00);" 
//            ); 
//foreach($queries as $query){ 
//    $sqlite->query($query); 
//} 

// use the new function in a query 
$sqlite->query("SELECT name, quantity, price FROM test"); 

$row = $sqlite->returnRows(); 
echo '<pre>'; 
print_r($row); 
echo '</pre>'; 

$sqlite->close(); 
unset($sqlite); 
//close sqlitedb.db
fclose($handle);

?> 
