<HTML><BODY>

This sample PHP script shows how to create a SQLite database.  
It will create a directory called dbdir and a database called 
sqlitedb.db within it.
Run this script after downloading microweb to your hard drive, 
not from a cd rom. 

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


function purge($dir) {
    // function to recurse into a directory and empty it
    // call it like this: purge("/dir/")
    // remember the trailing slash!
    
    $handle = opendir($dir);
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
	        if (is_dir($dir.$file)) {
                purge ($dir.$file."/");
                rmdir($dir.$file);
        	}
            else {
    	        unlink($dir.$file);
            }
        }
    }
    closedir($handle); 
    rmdir($dir) or die ("Could not remove directory $dir\n");
}




$dbdir = "../dbdir";
if (is_dir($dbdir)) { purge("$dbdir/"); } // erase old database directory
mkdir($dbdir) or die ("Could not make directory"); //make databse directory

$sqlite =& new SPSQLite($dbdir . '/sqlitedb.db');
$query ="CREATE TABLE test(id INTEGER PRIMARY KEY, name VARCHAR(25), quantity INTEGER, price NUMERIC(5,2));"; 

$sqlite->query($query); 

// insert data 
$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); 
} 

//$sqlite->query("SELECT name, quantity, price FROM test"); 
//$row = $sqlite->returnRows(); 
//echo '<pre>'; 
//print_r($row); 
//echo '</pre>'; 
$sqlite->close(); 
unset($sqlite);

print ("<br><br>Database has been created\n");
?>
</body>

