|
|
@@ -98,6 +98,21 @@ abstract class Table {
|
|
|
//@param $attr 数组,键值参考add()
|
|
|
public function edit($id, $attr){}
|
|
|
|
|
|
+ //修改指定字段
|
|
|
+ public function update($id, $attrs)
|
|
|
+ {
|
|
|
+ $params = array();
|
|
|
+ foreach ($attrs as $key => $value) {
|
|
|
+ //$type = self::getTypeByAttr($key);
|
|
|
+ $params[$this->table_name.'_'.$key] = array('string', $value);
|
|
|
+
|
|
|
+ }
|
|
|
+ //where条件
|
|
|
+ $where = array( $this->table_id => array("number", $id));
|
|
|
+ //返回结果
|
|
|
+ $r = $this->pdo->sqlupdate($this->table_fullname, $params, $where);
|
|
|
+ return $r;
|
|
|
+ }
|
|
|
|
|
|
//--------------------------------------------------
|
|
|
//------------依赖于字段设置的常见方法,可以重载----
|
|
|
@@ -175,6 +190,14 @@ abstract class Table {
|
|
|
$val = $this->pdo->sql_check_input(array('string', $val));
|
|
|
$where .= " and $field_name = $val ";
|
|
|
}
|
|
|
+ if($operator == '>num'){//大于数字
|
|
|
+ $val = $this->pdo->sql_check_input(array('number', $val));
|
|
|
+ $where .= " and $field_name > $val ";
|
|
|
+ }
|
|
|
+ if($operator == '<num'){//小于数字
|
|
|
+ $val = $this->pdo->sql_check_input(array('number', $val));
|
|
|
+ $where .= " and $field_name < $val ";
|
|
|
+ }
|
|
|
|
|
|
if($operator == '%s'){//字符串,模糊搜索
|
|
|
$val = '%'.$val.'%';
|
|
|
@@ -182,6 +205,51 @@ abstract class Table {
|
|
|
$where .= " and $field_name like $val " ;
|
|
|
}
|
|
|
|
|
|
+ if($operator == '=n_arr'){//or 连接的数字数组
|
|
|
+ $where .= " and (";
|
|
|
+ $first = true;
|
|
|
+ foreach ($val as $item) {
|
|
|
+ if ($first) {
|
|
|
+ $where .= " $field_name = $item ";
|
|
|
+ $first = false;
|
|
|
+ } else {
|
|
|
+ $where .= " or $field_name = $item ";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $where .= ") ";
|
|
|
+ }
|
|
|
+
|
|
|
+ if($operator == '=date'){//时间戳在当天
|
|
|
+ $val = $this->pdo->sql_check_input(array('number', $val));
|
|
|
+ if (empty($val)) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ $begin = $val; //不分时区
|
|
|
+ $end = $val + 24*60*60;
|
|
|
+ $where .= " and ($field_name >= $begin and $field_name < $end) ";
|
|
|
+ }
|
|
|
+
|
|
|
+ if($operator == 'date2date'){//时间戳在两天之间
|
|
|
+ if (!empty($val[0])) {
|
|
|
+ $begin = $val[0] - 8*60*60; //东8时区
|
|
|
+ $where .= " and $field_name >= $begin ";
|
|
|
+ }
|
|
|
+ if (!empty($val[1])) {
|
|
|
+ $end = $val[1] + 16*60*60;
|
|
|
+ $where .= " and $field_name < $end ";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if($operator == 'id_in_arr'){//id在数组中
|
|
|
+ $where .= " and (1=0 ";
|
|
|
+ foreach ($val as $tempId) {
|
|
|
+ $tempId = $this->pdo->sql_check_input(array('number', $tempId));
|
|
|
+ $where .= " or $field_name=$tempId ";
|
|
|
+ }
|
|
|
+ $where .= ") ";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
return $where;
|
|
|
}
|