PHP SQLite類代碼。
代碼如下:
<? /** * SQLite類 * 2009-5-6 * 連萬春 * */ class SQLite { // 當前SQL指令 public $_mQueryStr = ''; // 當前結果 public $_mResult = null; // SQLite串連控制代碼 protected $_mSqlite; // 警告資訊 protected $_mErrorInfo; /** * 資料庫連接 構造類 * * @param string $databaseFile 資料庫檔案 * @return unknown */ public function construct($databaseFile){ if(file_exists($databaseFile)){ $this->_mSqlite = new PDO('sqlite:'.$databaseFile); }else{ $this->_mErrorInfo="未找到資料庫檔案"; return false; } } /** * 資料庫有返回結果的語句操作 * * @param srting $sql SQL語句 * @return unknown */ public function getAll($sql){ if (empty($sql)) { $this->_mErrorInfo="SQL語句錯誤"; return false; } $result=$this->_mSqlite->prepare($sql); if ( false === $result) { return array(); } $result->execute(); $this->_mResult = $result->fetchAll(); if ( false === $this->_mResult) { return array(); } return $this->_mResult; } /** * 執行INSERT,DELETE,UPDATA操作 * * @param srting $sql SQL語句 * @return unknown */ public function query($sql){ if (empty($sql)) { $this->_mErrorInfo="SQL語句錯誤"; return false; } //$this->_mSqlite->exec($sql)or die(print_r($this->_mSqlite->errorInfo())); $this->_mSqlite->exec($sql); return true; } /** * 返回錯誤資訊 * * @return unknown */ public function setError(){ return $this->_mErrorInfo; } } ?>