首页 > php, sqlite > php连接SQLite类
2010四月14

php连接SQLite类

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();
}
}
/*
//然后实例化
$DB=new SQLite(‘blog.db’); //这个数据库文件名字任意
//创建数据库表
$DB->Query(“create table test(id integer primary key,title varchar(50)”);
//添加数据
$DB->Query(“insert into test(title) values(‘泡菜’)”);
$DB->Query(“insert into test(title) values(‘蓝雨’)”);
$DB->Query(“insert into test(title) values(‘Ajan’)”);
$DB->Query(“insert into test(title) values(‘傲雪蓝天’)”);
//循环
$SQL=’select title from test order by id desc’;
foreach($DB->Query($SQL) as $RS){
echo $RS['title'];
}
*/
普通的连接方法
$dsn = ‘sqlite:ddd.db3′;

$dbh = new pdo($dsn, $user, $password);
$sth = $dbh->prepare(‘SELECT *FROM chen_admin’);
$sth->execute();
while($result = $sth->fetchAll()){
echo $result['id'];
}

文章作者:admin
本文地址:http://www.chenguangfu.cn/?p=15
版权所有 © 转载时必须以链接形式注明作者和原始出处!

本文目前尚无任何评论.

发表评论

网站备案号:蜀ICP备12008905号 川公网安备51010802032125