相關(guān)關(guān)鍵詞
關(guān)于我們
最新文章
- PHP中opcode緩存簡(jiǎn)單用法分析
- thinkPHP控制器變量在模板中的顯示方法示例
- PHP move_uploaded_file() 函數(shù)(將上傳的文件移動(dòng)到新位置)
- dirname(__FILE__)的含義和應(yīng)用說(shuō)明
- thinkPHP5框架實(shí)現(xiàn)分頁(yè)查詢功能的方法示例
- PHP中單雙號(hào)與變量
- PHP獲得當(dāng)日零點(diǎn)時(shí)間戳的方法分析
- Laravel ORM對(duì)Model::find方法進(jìn)行緩存示例詳解
- PHP讀寫文件高并發(fā)處理操作實(shí)例詳解
- 【CLI】利用Curl下載文件實(shí)時(shí)進(jìn)度條顯示的實(shí)現(xiàn)
PHP實(shí)現(xiàn)的簡(jiǎn)單操作SQLite數(shù)據(jù)庫(kù)類與用法示例
本文實(shí)例講述了PHP實(shí)現(xiàn)的簡(jiǎn)單操作SQLite數(shù)據(jù)庫(kù)類與用法。分享給大家供大家參考,具體如下:
SQLite是一款輕型的數(shù)據(jù)庫(kù),是遵守ACID的關(guān)聯(lián)式數(shù)據(jù)庫(kù)管理系統(tǒng),它的設(shè)計(jì)目標(biāo)是嵌入式的,而且目前已經(jīng)在很多嵌入式產(chǎn)品中使用了它,它占用資源非常的低,在嵌入式設(shè)備中,可能只需要幾百K的內(nèi)存就夠了。它能夠支持Windows/Linux/Unix等等主流的操作系統(tǒng),同時(shí)能夠跟很多程序語(yǔ)言相結(jié)合,比如Tcl、PHP、Java等,還有ODBC接口,同樣比起MySQL、PostgreSQL這兩款開(kāi)源世界著名的數(shù)據(jù)庫(kù)管理系統(tǒng)來(lái)講,它的處理速度比他們都快。
這里為大家提供一個(gè)簡(jiǎn)潔的PHP操作SQLite類:
<?php /*** //應(yīng)用舉例 require_once('cls_sqlite.php'); //創(chuàng)建實(shí)例 $DB=new SQLite('blog.db'); //這個(gè)數(shù)據(jù)庫(kù)文件名字任意 //創(chuàng)建數(shù)據(jù)庫(kù)表。 $DB->query("create table test(id integer primary key,title varchar(50))"); //接下來(lái)添加數(shù)據(jù) $DB->query("insert into test(title) values('泡菜')"); $DB->query("insert into test(title) values('藍(lán)雨')"); $DB->query("insert into test(title) values('Ajan')"); $DB->query("insert into test(title) values('傲雪藍(lán)天')"); //讀取數(shù)據(jù) print_r($DB->getlist('select * from test order by id desc')); //更新數(shù)據(jù) $DB->query('update test set title = "三大" where id = 9'); ***/ class SQLite { function __construct($file) { try { $this->connection=new PDO('sqlite:'.$file); } catch(PDOException $e) { try { $this->connection=new PDO('sqlite2:'.$file); } catch(PDOException $e) { exit('error!'); } } } function __destruct() { $this->connection=null; } function query($sql) //直接運(yùn)行SQL,可用于更新、刪除數(shù)據(jù) { return $this->connection->query($sql); } function getlist($sql) //取得記錄列表 { $recordlist=array(); foreach($this->query($sql) as $rstmp) { $recordlist[]=$rstmp; } return $recordlist; } 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(); } } ?>