2009年7月15日 星期三

用 php 寫一個簡單的 sqlite 資料庫


$newdb ="stock.sqlite";
$table ="ase";
$db=sqlite_open($newdb,0666,$sqlerr);
if( $db )
{
$Q1=sqlite_query($db,"select count(serial) from ase");
if ( !$Q1 )
{
echo "Create $table
";
sqlite_query($db,"create table $table (serial int not null,name char(255),primary key(serial))");
$Q1=sqlite_query($db,"select count(serial) from ase");
}
$record=sqlite_fetch_array($Q1);
$id=intval($record[0]);
if( $id==0 )
{ // no record, add some record
echo "Insert $table
";
$id++;sqlite_query($db,"insert into $table (serial,name) values ('$id','第一筆')");
$id++;sqlite_query($db,"insert into $table (serial,name) values ('$id','第二筆')");
$id++;sqlite_query($db,"insert into $table (serial,name) values ('$id','第三筆')");
$id++;sqlite_query($db,"insert into $table (serial,name) values ('$id','第四筆')");
$id++;sqlite_query($db,"insert into $table (serial,name) values ('$id','第五筆')");
$id++;sqlite_query($db,"insert into $table (serial,name) values ('$id','第六筆')");
}
sqlite_close($db);
}
fclose($fin);

?>

沒有留言: