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 GD库生成图像的几个函数总结

使用GD库中提供的函数动态绘制完成图像以后,就需要输出到浏览器或者将图像保存起来。在PHP中,可以将动态绘制完成的画布,直接生成GIF、JPEG、PNG和WBMP四种图像格式。可以通过调...

PHP安全技术之 实现php基本安全

1.不要依赖注册全局变量功能(register_globals) 注册全局变量的出现曾经让PHP变得非常易用,但也降低了安全性(方便之处经常会破坏安全性)。建议在编程时把register...

使用array mutisort 实现按某字段对数据排序

array_multisort 的用法 一、先看最简单的情况。有两个数组:$arr1 = array(1,9,5);$arr2 = array(6,2,4);array_multisor...

效率较高的php下读取文本文件的代码 原创

 fread :以字节位计算长度,按照指定的长度和次数读取数据,遇到结尾或完成指定长度读取后停止.  fgets :整行读取,遇到回车换行或结尾停...

phplock(php进程锁) v1.0 beta1

在web开发中我们经常对我们的数据库耗时操作做缓存,但是可能出现一个陷阱,在缓存失效的一瞬间,大量的访问得到缓存失效的标示,都去后端查询数据库,导致同时大量的数据库耗时查询,出现数据库宕...