<?php
// uncomment extension=php_pdo_sqlite.dll และ extension=php_sqlite3.dll ใน php.ini
class MyDB extends SQLite3 {
function __construct() { $this->open('oedb.db'); }
}
$db = new MyDB();
if(!$db) { echo $db->lastErrorMsg(); } else { echo "Opened database successfully\n"; }
$sql =<<<EOF
SELECT * from mem;
EOF;
$ret = $db->query($sql);
while($row = $ret->fetchArray(SQLITE3_ASSOC) ) {
echo "ID = ". $row['myid'] . " ";
echo "NAME = ". $row['myname'] ." ";
echo "SALARY = ". $row['mysalary'] ."\n";
}
echo "Operation done successfully\n";
$db->close();
$dbl = new SQLite3('oedb.db');
$resultsl = $dbl->query('SELECT *FROM mem');
while ($rowl = $resultsl->fetchArray()) {
var_dump($rowl);
}
$dbl->close();
$dbi = new SQLite3('oedb.db');
$resultsi = $dbi->exec('insert into mem values(2,"test",222)');
$dbi->close();
$pdo = new PDO('sqlite:oedb.db');
$pdo->exec('insert into mem values(4,"test",444)');
$pdos = new PDO('sqlite:oedb.db');
try {
$stmt = $pdos->prepare('select * from mem where myid=4');
$stmt->execute();
} catch (Exception $e) {
die ($e);
}
foreach ($stmt as $row) { echo $row['myname'];}
$pdos2 = new PDO('sqlite:oedb.db');
$stmt = $pdos2->query('select * from mem');
while ($r = $stmt->fetchObject()) { echo $r->myid; }
?>