Home  >  Article  >  php教程  >  封装的Sqlite3简易操作类

封装的Sqlite3简易操作类

PHP中文网
PHP中文网Original
2016-05-23 16:38:48989browse

封装的Sqlite3简易操作类  

封装的Sqlite3简易操作类,基于Sqlite3扩展写的,用法和前一个Mysql一样。
但是要注意的是,数据库不存在时会自动创建一个,但是自动创建的数据库类型是Sqlite2数据库,这个要注意下。

url=$url;
        $this->open($url);
    }
    function check_input($value){
        if (get_magic_quotes_gpc()) {
            $value = sqlite_escape_string($value);
        }
        return $value;
    }
    function create($table,$name,$type=null){
        $sql = 'CREATE TABLE '.$table.'(';
        if($type==null){
            $arrname = array_keys($name);
            $arrtype = array_values($name);
        }else{
            $arrname = explode("|", $name);
            $arrtype = explode("|", $type);
        }
        for($i=0;$iquery($sql);
        if($re){
            return true;
        }else{
            return fasle;
        }
    }
    function drop($table){
        $sql = 'DROP TABLE '.$table.';';
        $re = $this->query($sql);
        if($re){
            return true;
        }else{
            return false;
        }
    }
    function insert($table,$name,$value=null){
        $sql = "INSERT INTO ".$table.'(';
        if($value == null){
        $arrname = array_keys($name);
        $arrvalue = array_values($name);
        }else{
        $arrname = explode('|', $name);
        $arrvalue = explode('|', $value);
        }
        for($i=0;$iquery($sql);
        if($re){
            return true;
        }else{
            return false;
        }
    }
    function delete($table,$Conditionsname,$Conditionsvalue=null){
        if($Conditionsvalue!=null){
            $sql = "DELETE FROM ".$table." WHERE ".$Conditionsname."='".$Conditionsvalue."';";
        }else{
            $sql = "DELETE FROM ".$table." WHERE ";
            $arrname = array_keys($Conditionsname);
            $arrvalue = array_values($Conditionsname);
            for($i=0;$iquery($sql);
        if($re){
            return true;
        }else{
            return false;
        }
    }
    function select($table,$name,$Conditionsname,$Conditionsvalue=null){
        if($Conditionsvalue!=null){
            $sql = "SELECT ".$name." FROM ".$table." WHERE ".$Conditionsname."='".$Conditionsvalue."';";
        }else{
            $sql = "SELECT ".$name." FROM ".$table." WHERE ";
            $arrname = array_keys($Conditionsname);
            $arrvalue = array_values($Conditionsname);
            for($i=0;$iquery($sql);
        $row = $ret->fetchArray(SQLITE3_ASSOC);
        return $row[$name];
    }
    function update($table,$name,$value,$Conditionsname,$Conditionsvalue=null){
        if($Conditionsvalue!=null){
            $sql = "UPDATE ".$table." SET ".$name."= '".$value."' WHERE ".
            $Conditionsname."='".$Conditionsvalue."';";
        }else{
            $sql = "UPDATE ".$table." SET ".$name."= '".$value."' WHERE ";
            $arrname = array_keys($Conditionsname);
            $arrvalue = array_values($Conditionsname);
            for($i=0;$iquery($sql);
        if($re){
            return true;
        }else{
            return false; 
        }
    }
    function group($table,$name){
        $sql = "SELECT ".$name." FROM ".$table.";";
        $return = array();
        $ret = $this->query($sql);
        while($row = $ret->fetchArray(SQLITE3_ASSOC) ){
            array_push($return, $row[$name]);
        }
        return $return;
    }
    function fecthall($sql){
        $return = array();
        $ret = $this->query($sql);
        while($row = $ret->fetchArray(SQLITE3_ASSOC) ){
            array_push($return, $row);
        }
        return $return;
    }
}

       

 以上就是封装的Sqlite3简易操作类的内容,更多相关内容请关注PHP中文网(m.sbmmt.com)!

Statement:
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