>  기사  >  백엔드 개발  >  PHP SQLite 클래스(예제 코드)

PHP SQLite 클래스(예제 코드)

怪我咯
怪我咯원래의
2017-07-04 14:15:501865검색

PHP SQLite 클래스 코드.

코드는 다음과 같습니다.

<? 
/** 
* 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; 
    } 
} 
?>

위 내용은 PHP SQLite 클래스(예제 코드)의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.