PHP SQLite class (example code)

怪我咯
Release: 2023-03-12 16:04:02
Original
1917 people have browsed it

PHP SQLite class code.

The code is as follows:

<? 
/** 
* SQLite类 
* 2009-5-6 
* 连万春 
* 
*/ 
class SQLite { 
    // 当前SQL指令 
    public $_mQueryStr = &#39;&#39;; 
    // 当前结果 
    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(&#39;sqlite:&#39;.$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; 
    } 
} 
?>
Copy after login

The above is the detailed content of PHP SQLite class (example code). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!