SQL组装-单个或数组参数过滤。在Dao中使用
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $val | String|Array | 是 | SQL组装数据 |
| $iskey | Int | 否 | 0-过滤value值,1-过滤字段 |
class testaDao extends Dao {
public $db = 'test';
public function test() {
echo $this->dao->db->build_escape($val, $iskey = 0);
}
}
SQL组装-将数组值通过,隔开 。在Dao中使用
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $val | Array | 是 | SQL组装数据,返回:'1','2','3' |
| $iskey | Int | 否 | 0-过滤value值,1-过滤字段 |
class testaDao extends Dao {
public $db = 'test';
public function test() {
echo $this->dao->db->build_implode(array('test' => 'test1'), $iskey = 0);
}
}
SQL组装-组装IN语句 。在Dao中使用
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $val | String|Array | 是 | SQL组装数据, 例如:ID:array(1,2,3)。返回:('1','2','3') |
class testaDao extends Dao {
public $db = 'test';
public function test() {
echo $this->dao->db->build_in(array(2,3,4));
}
}
SQL组装-组装IN语句 。在Dao中使用
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $value | String | 是 | 参数规则:array('key' => 'value'),返回:(id,username) VALUES ('ss', 'sadsa') |
class testaDao extends Dao {
public $db = 'test';
public function test() {
echo $this->dao->db->build_insert( array('key' => 'value'));
}
}
SQL组装-组装多条语句插入。在Dao中使用
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $field | Array | 是 | 字段 |
| $value | Array | 是 | 值:array(array('test1'),array('test2')),返回:('key') VALUES ('value'),('value2') |
class testaDao extends Dao {
public $db = 'test';
public function test() {
echo $this->dao->db->build_insertmore(array('username'), array(array('zhuli'), array('woshishen')));
}
}
SQL组装-组装多条语句插入。在Dao中使用
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $k | String | 是 | KEY值 |
| $v | String | 是 | VALUE值 返回:a = 'a' |
class testaDao extends Dao {
public $db = 'test';
public function test() {
echo $this->dao->db->build_kv('asd', 'asdas');
}
}
SQL组装-组装LIMIT语句。在Dao中使用
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $start | Int | 是 | 开始 |
| $num | Int | 是 | 条数 返回:LIMIT 0,10 |
class testaDao extends Dao {
public $db = 'test';
public function test() {
echo $this->dao->db->build_limit(100,200);
}
}
SQL组装-组装UPDATE语句 。在Dao中使用
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $val | Array | 是 | 数组参数,返回:SET name = 'aaaaa' |
class testaDao extends Dao {
public $db = 'test';
public function test() {
echo $this->dao->db->build_update(array('username' => 'asdas'));
}
}
SQL组装-组装AND符号的WHERE语句 。在Dao中使用
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $val | Array | 是 | 数组参数,返回:WHERE a = 'a' AND b = 'b' |
class testaDao extends Dao {
public $db = 'test';
public function test() {
// WHERE `sad` = 100
echo $this->dao->db->build_where(array('sad'=>100));
// WHERE `age` IN ('15', '18', '19')
echo $this->dao->db->build_where(array('age'=>array(15,18,19)));
// WHERE `age`>15 AND `age`<20
echo $this->dao->db->build_where(array('age'=>array('>'=>15, '<'=>20)));
// WHERE `age` like '%sad%'
echo $this->dao->db->build_where(array('name'=>array('like'=>'%sad%')));
}
}
检查DAO中进来的数组参数是否key键存在
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $data | Array | 是 | 数组结构,例如:array("username" => 'asdasd') |
| $fields | String | 是 | 例如:"username,password" |
class userDao extends Dao {
public $table_name = 'user';
private $fields = "username,password";
/**
* 新增用户
* @param $user
*/
public function addUser($user) {
$user = $this->dao->db->build_key($user, $this->fields);
return $this->dao->db->insert($user, $this->table_name);
}
}