PHP SQLite类

yipeiwu_com5年前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通过header实现文本文件下载的代码

这就是今天讨论的主要问题。PHP帮助文档里面关于PHP通过header触发下载的说明比较简单,而网上关于此方面的文章也少的可怜,有很多文章都无法实现所需要的效果。今天我也来谈一下这个方面...

php中strlen和mb_strlen用法实例分析

本文实例分析了php中strlen和mb_strlen用法。分享给大家供大家参考,具体如下: 首先看如下代码(文件编码utf8): <?php $utf8_string...

非常经典的PHP文件上传类分享

文件上传是项目开发中比较常见的功能,但文件上传的过程比较繁琐,只要是有文件上传的地方就需要编写这些复杂的代码。为了能在每次开发中降低功能的编写难度,也为了能节省开发时间,通常我们都会将这...

PHP将进程作为守护进程的方法

本文实例讲述了PHP将进程作为守护进程的方法。分享给大家供大家参考。具体分析如下: php中posix_setsid()的用法 文档解释是“Make the current proces...

PHP实现的权重算法示例【可用于游戏根据权限来随机物品】

本文实例讲述了PHP实现的权重算法。分享给大家供大家参考,具体如下: 假设有数据: $data = array ( array ( 'id' => 1, 'name' =...