网上说 PHP 5 开始集成 SQLite 数据库操作,但是我 $db = @sqlite_open("db.db"); 打不开数据库。
我用下面的方法成功了:<?php
class SQLite{
function __construct($file){
try{
$this->Connection=new PDO('sqlite2:'.$file);
}catch(PDOException $e){
try{
$this->Connection=new PDO('sqlite:'.$file);
}catch(PDOException $e){
exit('error!');
}
}
}
function __destruct(){
$this->Connection=null;
}
function Query($SQL){
return $this->Connection->Query($SQL);
}
function Execute($SQL){
return $this->Query($SQL)->fetch();
}
function RecordArray($SQL){
return $this->Query($SQL)->fetchAll();
}
function RecordCount($SQL){
return count($this->RecordArray($SQL));
}
function RecordLastID(){
return $this->Connection->lastInsertId();
}
}
?>