PHP SQLite类

yipeiwu_com6年前PHP代码库
复制代码 代码如下:

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

相关文章

PHP实现设计模式中的抽象工厂模式详解

PHP实现设计模式中的抽象工厂模式详解

抽象工厂模式(Abstact Factory)是一种常见的软件设计模式。该模式为一个产品族提供了统一的创建接口。当需要这个产品族的某一系列的时候,可以为此系列的产品族创建一个 具体的工厂...

基于PHP服务端图片生成缩略图的方法详解

复制代码 代码如下:<?php//定义缩略图片尺寸$picSize = array(        ...

php数组函数序列 之array_count_values() 统计数组中所有值出现的次数函数

array_count_values()定义和用法 array_count_values() 函数用于统计数组中所有值出现的次数。 本函数返回一个数组,其元素的键名是原数组的值,键值是该...

phpadmin如何导入导出大数据文件及php.ini参数修改

最近遇到了数据库过大的时候用phpadmin导入的问题,新版本的phpadmin导入限定是8M,老版本的可能2M,我的数据库有几十兆这可怎么办呢? 首先如果你有独立服务器或vps的话可以...

解析PHP函数array_flip()在重复数组元素删除中的作用

我们都知道,PHP中的数组元素删除的方式可以有很多种,经常用到的函数有php中array_unique()。那么我们今天为大家介绍的PHP函数array_flip()在删除数组重复元素时...