4 Star 14 Fork 5

Egist / service_count

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
usql.php 3.04 KB
一键复制 编辑 原始数据 按行查看 历史
Egist 提交于 2016-12-10 22:00 . Upload usql.php
<?php
$m=new usql();
class usql{
private $db;
public $sql=array("from"=>"","where"=>"","order"=>"","limit"=>"","update"=>"","select"=>"","set"=>"","delete"=>"","insert"=>"");
public $sentence;
function __construct($type="mysql",$host="localhost",$name="test",$user="root",$pass="maysrpldn"){
$dsn=$type.":host=".$host.";dbname=".$name;
$this->db=new PDO($dsn,$user,$pass);
}
function select($sel="*"){
$this->sql['select']=" SELECT ".$sel;
return $this;
}
function where($info){
$this->sql['where']=" WHERE ";
if(is_array($info)){
if(strtolower($info['_logic'])=="or"){
unset($info['_logic']);
foreach ($info as $key => $value) {
$this->sql['where']=$this->sql['where']." OR ".$key." = ".$value;
}
}elseif(strtolower($info['_logic'])=="and"){
unset($info['_logic']);
foreach ($info as $key => $value) {
$this->sql['where']=$this->sql['where']." AND ".$key." = ".$value;
}
}else{
if(count($info)==1){
$key=key($info);
$value=$info[$key];
$this->sql['where']=" WHERE ".$key."='".$value."'";
}else{
foreach ($info as $key => $value) {
$this->sql['where']=$this->sql['where']." AND ".$key." = ".$value;
}
}
}
}else{
$this->sql['where']=" WHERE ".$info;
}
return $this;
}
function order($key,$type="desc"){
$this->sql['order']=" ORDER BY ".$key." ".$type;
return $this;
}
function from($table){
$this->sql['from']=" FROM ".$table;
return $this;
}
function limit($start=1,$count=10){
$this->sql['limit']=" LIMIT ".$start." ".$count;
return $this;
}
function update($table){
$this->sql['upadte']=" UPDATE ".$table;
return $this;
}
function set($array){
$this->sql['set']=" SET ";
foreach ($array as $key => $value) {
$this->sql['set']=$this->sql['set']." ".$key."=".$value.",";
}
$this->sql['set']=substr($this->sql['set'], 0,-1);
return $this;
}
function delete($table){
$this->sql['delete']=" DELETE ".$table;
return $this;
}
function insert($table,$array){
$this->sql['insert']="INSERT INTO ".$table;
foreach ($array as $key => $value) {
$k_a[]=$key;
$v_a[]=$value;
}
$str_1=implode(",", $k_a);
$str_2=implode(",", $v_a);
$this->sentence=$this->sql['insert']." (".$str_1.") VALUES ( ".$str_2.")";
}
function query($sql){
return $this->db->query($sql);//SELECT
}
function exec($sel){
return $this->db->exec($sql);//INSERT UPADTE DELETE
}
function s_del($array){//简的通过一个key对应value删除
$key=key($array);
$value=$array[$key];
$this->sentense="DELETE".$this->sql['from']."WHERE ".$key."='".$value."'";
$this->exec($this->sentence);
}
}
PHP
1
https://gitee.com/supercell/service_count.git
git@gitee.com:supercell/service_count.git
supercell
service_count
service_count
master

搜索帮助