自用的PHP sqlite3 封装操作类
侧边栏壁纸
博主昵称
Moe

  • 累计撰写 11 篇文章
  • 累计收到 1 条评论

自用的PHP sqlite3 封装操作类

admin
2022-03-10 / 0 评论 / 57 阅读 / 正在检测是否收录...

先笔记一下 后续可能还会修改

//Sqlite3 封装类 自用
class _sqlite extends SQLite3
{
    function __construct($filename)
    {
        $this->open($filename);
    }

 public function __I($arr,$title)
    {
$sql.="INSERT INTO {$title} VALUES (";        
        foreach ($arr as $val) {
            $sql.=$val;
            if (next($arr)==true)$sql.= ",";
        }

$sql.=");";

            //$ret = $this->exec($sql);
            return $sql;;
}
    public function __t($id,$title)
    {
        if($id=="s"){
            $sql = "SELECT * FROM {$title} ";
        }elseif($id=="d"){
            $sql = "DELETE FROM {$title} ";
        }elseif($id=="u"){
            $sql = "UPDATE {$title} SET ";
        }
        return $sql;
    }
     public function __S($arr)
    {
        foreach ($arr as $key => $val) {
            $sql.=$key . " = ";
            if(is_numeric($val)){
                $sql.="{$val}"; 
            }else{
                $sql.="'{$val}'";
            }
            if($val !== end($arr))$sql.= ",";
        }
    return $sql;
}
    
    
    public function __W($sql)
    {
        $sql = " WHERE " . $sql;
        return $sql;
    }
    public function __BY($id)
    {
        if($id=="a"){
            $sql = " ORDER BY {$title} asc";
        }elseif($id=="d"){
        $sql = " ORDER BY {$title} DESC";
    }
    return $sql;
        
    }
    public function __L($sql)
    {
            $sql = " LIMIT ".$sql;
    return $sql;
    }
    public function __Q($sql)
    {
            $ret = $this->query($sql);
            return $ret;
    }
    
    public function __QR($sql)
    {
            $ret = $this->query($sql);
            $row = $ret->fetchArray(SQLITE3_ASSOC);
            return (array)$row;
    }
    public function __QRW($sql)
    {
            $ret = $this->query($sql);
            while($row = $ret->fetchArray(SQLITE3_ASSOC)){
                $row2[] = $row;
            }
            return (array)$row2;
    }

    public function __QC($sql)
    {
            $ret = $this->exec($sql);
            return $ret;
    
    }
    public function __IDSET()
    {
            $ret = "NTEGER PRIMARY KEY     NOT NULL";
            return $ret;
    
    }
    public function __CR($arr,$title)
    {
        foreach($arr as $key =>$val){
            $sql.=$val;
            if($val !== end($arr))$sql.= ",";
        }
        
   $sql ="CREATE TABLE {$title} ({$sql});";
        return $sql;
    }
}

纯新手写,大佬轻喷哈~

0

评论 (0)

取消