<?php
/**
* Created by ZhengNiu.
* User: 77103
* Date: 2019/4/4
* Time: 15:19
*/
namespace app\helper;
class db
{
private $sql = [
'table' => '',
'field' => '*',
'where' => '',
'order' => '',
'limit' => ''
];
protected $where = '';
protected $order = '';
protected $limit = '';
public function __call($name, $arguments)
{
if (array_key_exists($name, $this->sql)) {
$this->sql[$name] = $arguments[0];
}
return $this;
}
public function select()
{
if (!empty($this->sql['where'])) {
$this->where = ' where ' . $this->sql['where'];
}
if (!empty($this->sql['order'])) {
$this->order = ' order by ' . $this->sql['order'];
}
if (!empty($this->sql['limit'])) {
$this->limit = ' limit ' . $this->sql['limit'];
}
$sql = 'select ' . $this->sql['field'] . ' from ' . $this->sql['table'] . $this->where . $this->order . $this->limit;
echo $sql;
}
}
// 调用
$db = new db();
$db->table('user')->field('id,username,email,age')->where("email like '%qq.com%'")->order('id desc')->limit('1,10')->select();
Logic::vd($db);