| | |
| | | <?php |
| | | |
| | | /* |
| | | * $Author :PHPYUN开发团队 |
| | | * |
| | |
| | | * |
| | | * 软件声明:未经授权前提下,不得用于商业运营、二次开发以及任何形式的再次发布。 |
| | | */ |
| | | |
| | | class model{ |
| | | // 操作状态 |
| | | const MODEL_INSERT = 1; // 插入模型数据 |
| | |
| | | const VALUE_VALIDATE = 2; // 表单值不为空则验证 |
| | | |
| | | //网站配置信息 |
| | | protected $config = null; |
| | | protected $config = NULL; |
| | | // 当前数据库操作对象 |
| | | protected $db = null; |
| | | protected $db = NULL; |
| | | // 主键名称 |
| | | protected $pk = 'id'; |
| | | // 主键是否自动增长 |
| | | protected $autoinc = false; |
| | | protected $autoinc = FALSE; |
| | | // 数据表前缀 |
| | | protected $def = null; |
| | | protected $def = NULL; |
| | | // 模型名称 |
| | | protected $name = ''; |
| | | // 数据库编码 |
| | |
| | | protected $_map = array(); // 字段映射定义 |
| | | protected $_scope = array(); // 命名范围定义 |
| | | // 是否自动检测数据表字段信息 |
| | | protected $autoCheckFields = true; |
| | | protected $autoCheckFields = TRUE; |
| | | // 是否批处理验证 |
| | | protected $patchValidate = false; |
| | | protected $patchValidate = FALSE; |
| | | // 链操作方法列表 |
| | | protected $methods = array('order','alias','having','group','lock','distinct','auto','filter','validate','result','token'); |
| | | //开启分站功能的数据表 |
| | |
| | | $protocol = 'http://'; |
| | | } |
| | | |
| | | if(strpos($this->config['sy_wapdomain'],'http://')===false && strpos($this->config['sy_wapdomain'],'https://')===false) |
| | | { |
| | | if (strpos($this->config['sy_wapdomain'], 'http://') === FALSE && strpos($this->config['sy_wapdomain'], 'https://') === FALSE) { |
| | | $this->config['sy_wapdomain'] = $protocol.$this->config['sy_wapdomain']; |
| | | } |
| | | } |
| | |
| | | * @return mixed |
| | | */ |
| | | public function __get($name) { |
| | | return isset($this->data[$name])?$this->data[$name]:null; |
| | | return isset($this->data[$name]) ? $this->data[$name] : NULL; |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | // 回调方法 初始化模型 |
| | | protected function _initialize() {} |
| | | |
| | | protected function _initialize() { |
| | | } |
| | | |
| | | |
| | | function insert_into($table,$data=array()){ |
| | |
| | | if(is_array($$TableFullName)){ |
| | | $fields=array_keys($$TableFullName); |
| | | }else{ |
| | | return false; |
| | | return FALSE; |
| | | } |
| | | |
| | | if(is_array($fields)){ |
| | |
| | | $value=@implode(",",$value); |
| | | return $this->DB_insert_once($table,$value); |
| | | } |
| | | |
| | | function update_once($table,$data=array(),$where=array()){ |
| | | |
| | | $this->db->connect(); |
| | | $value=array(); |
| | | include(PLUS_PATH.'dbstruct.cache.php'); |
| | | $TableFullName=$this->def.$table; |
| | | if(is_array($$TableFullName)){ |
| | | $fields=array_keys($$TableFullName); |
| | | }else{ |
| | | return false; |
| | | } |
| | | // $TableFullName=$this->def.$table; |
| | | // var_dump($$TableFullName);exit(); |
| | | // if (is_array($where)) { |
| | | // $fields = array_keys($where); |
| | | // } else { |
| | | // return FALSE; |
| | | // } |
| | | // var_dump($fields);exit(); |
| | | |
| | | if(is_array($fields)){ |
| | | |
| | | if(is_array($data)){ |
| | | |
| | | foreach($data as $key=>$v){ |
| | | |
| | | if(in_array($key,$fields)){ |
| | | |
| | | |
| | | if(is_array($v)){ |
| | | |
| | |
| | | |
| | | $value[] = "`".$key."`='".$this->db->escape_string($v)."'"; |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | return $this->DB_update_all($table,$value,$whereNew); |
| | | }else{ |
| | | return false; |
| | | return FALSE; |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | function FilterStr($str){ |
| | | $str = stripslashes($str); |
| | | return $str; |
| | | } |
| | | function Memcache_set($name,$value="") |
| | | { |
| | | |
| | | function Memcache_set($name, $value = "") { |
| | | |
| | | global $config; |
| | | |
| | | if(isset($config['ismemcache']) && $config['ismemcache']==2){ |
| | | return false; |
| | | return FALSE; |
| | | } |
| | | if (!empty($config['memcachehost']) && !empty($config['memcacheport']) && !empty($config['memcachetime'])){ |
| | | |
| | |
| | | |
| | | $memcache =new memcache(); |
| | | |
| | | if(!@class_exists($memcache)){return;} |
| | | if (!@class_exists($memcache)) { |
| | | return; |
| | | } |
| | | |
| | | $memcache->connect($memcachehost,$memcacheport) or die ("Memcache连接失败或您的服务器不支持Memcache,请在后台关闭!"); |
| | | |
| | |
| | | $memcache->close(); |
| | | return $val; |
| | | }else{ |
| | | return false; |
| | | return FALSE; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 通用数量查询$tablename,$where = 1, $select="*" |
| | | */ |
| | | function DB_select_num($tablename, $where = '', $select = "*",$tablename2='',$special=''){ |
| | | if(!$this->checkTableName($tablename)){ |
| | | |
| | | return false; |
| | | return FALSE; |
| | | } |
| | | $cachename=$tablename.$where; |
| | | if(!$return=$this->Memcache_set($cachename)){//获取是否存在memcache |
| | |
| | | } |
| | | $SQL = "SELECT count($select) as num FROM " . $this->def . $tablename; |
| | | |
| | | if($where) |
| | | { |
| | | if ($where) { |
| | | $SQL .= " WHERE ".$where; |
| | | } |
| | | } |
| | | $query = $this->db->query($SQL); |
| | | while($row=$this->db->fetch_array($query)){$return=$row['num'];} |
| | | while ($row = $this->db->fetch_array($query)) { |
| | | $return = $row['num']; |
| | | } |
| | | $this->Memcache_set($cachename,$return);//设置memcache |
| | | } |
| | | if($return<1){$return='0';} |
| | | if ($return < 1) { |
| | | $return = '0'; |
| | | } |
| | | return $return; |
| | | } |
| | | |
| | | function select_num($tablename, $where = array(), $select = "*"){ |
| | | if(!$this->checkTableName($tablename)){ |
| | | |
| | | return false; |
| | | return FALSE; |
| | | } |
| | | if($this->siteadmindir){ |
| | | if(in_array($tablename,$this->sitetable)){ |
| | |
| | | $SQL = "SELECT count($select) as num FROM " . $this->def . $tablename . $whereNew; |
| | | |
| | | $query = $this->db->query($SQL); |
| | | while($row=$this->db->fetch_array($query)){$return=$row['num'];} |
| | | while ($row = $this->db->fetch_array($query)) { |
| | | $return = $row['num']; |
| | | } |
| | | $this->Memcache_set($cachename,$return);//设置memcache |
| | | } |
| | | if($return<1){$return='0';} |
| | | if ($return < 1) { |
| | | $return = '0'; |
| | | } |
| | | return $return; |
| | | } |
| | | |
| | | /** |
| | | * 通用query查询 $tablename,$where = 1, $select="*" |
| | | *$special:标记某些特殊查询,不使用did参数。 |
| | |
| | | function DB_select_query($tablename, $where = 1, $select = "*",$special='') { |
| | | if(!$this->checkTableName($tablename)){ |
| | | |
| | | return false; |
| | | return FALSE; |
| | | } |
| | | if($this->siteadmindir){ |
| | | |
| | |
| | | $query=$this->db->query($SQL); |
| | | return $query; |
| | | } |
| | | |
| | | /** |
| | | * 通用all查询 $tablename,$where = 1, $select="*" |
| | | *$special:标记某些特殊查询,不使用did参数。 |
| | |
| | | function DB_select_all($tablename, $where = 1, $select = "*",$special='') { |
| | | if(!$this->checkTableName($tablename)){ |
| | | |
| | | return false; |
| | | return FALSE; |
| | | } |
| | | |
| | | $cachename=$tablename.$where; |
| | |
| | | } |
| | | |
| | | $query=$this->db->query($SQL); |
| | | while($row=$this->db->fetch_array($query)){$row_return[]=$row;} |
| | | while ($row = $this->db->fetch_array($query)) { |
| | | $row_return[] = $row; |
| | | } |
| | | $this->Memcache_set($cachename,$row_return);//设置memcache |
| | | } |
| | | return $row_return; |
| | |
| | | function select_all($tablename, $where = array(), $select = "*",$special='') { |
| | | if(!$this->checkTableName($tablename)){ |
| | | |
| | | return false; |
| | | return FALSE; |
| | | } |
| | | |
| | | if($this->siteadmindir && $special==''){ |
| | |
| | | } |
| | | return $row_return; |
| | | } |
| | | |
| | | /** |
| | | * 通用all查询双表 $tablename1,$tablename2, $where = 1, $select = "*" |
| | | */ |
| | | function DB_select_alls($tablename1,$tablename2, $where = 1, $select = "*") { |
| | | if(!$this->checkTableName($tablename1)){ |
| | | |
| | | return false; |
| | | return FALSE; |
| | | } |
| | | if(!$this->checkTableName($tablename2)){ |
| | | |
| | | return false; |
| | | return FALSE; |
| | | } |
| | | $cachename=$tablename1.$tablename2.$where; |
| | | if(!$row_return=$this->Memcache_set($cachename)){//获取是否存在memcache |
| | |
| | | $SQL = "SELECT $select FROM " . $this->def . $tablename1. " as a," . $this->def . $tablename2 . " as b WHERE $where"; |
| | | |
| | | $query=$this->db->query($SQL); |
| | | while($row=$this->db->fetch_array($query)){$row_return[]=$row;} |
| | | while ($row = $this->db->fetch_array($query)) { |
| | | $row_return[] = $row; |
| | | } |
| | | $this->Memcache_set($cachename,$row_return);//设置memcache |
| | | } |
| | | |
| | | return $row_return; |
| | | } |
| | | /** |
| | | |
| | | /** |
| | | * 单表单条插入 $tablename, $value |
| | | */ |
| | | function DB_insert_once($tablename, $value){ |
| | | if(!$this->checkTableName($tablename)){ |
| | | |
| | | return false; |
| | | return FALSE; |
| | | } |
| | | if(in_array($tablename,$this->sitetable) && strpos($value,'`did`')===false){ |
| | | if (in_array($tablename, $this->sitetable) && strpos($value, '`did`') === FALSE) { |
| | | $value.=",`did`='".$this->config['did']."'"; |
| | | } |
| | | $SQL = "INSERT INTO `" . $this->def . $tablename . "` SET ".$value; |
| | |
| | | // INSERT INTO `roles` (`uid`,`rid`) VALUES |
| | | // (534,14),(535,14),(536,14),(537,14),(539,14) |
| | | if(!$this->checkTableName($tablename)){ |
| | | return false; |
| | | return FALSE; |
| | | } |
| | | include(PLUS_PATH.'dbstruct.cache.php'); |
| | | $TableFullName=$this->def.$tablename; |
| | |
| | | return $return; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 更新 $tablename, $value, $where = 1 |
| | | */ |
| | | function DB_update_all($tablename, $value, $where ,$pecial=''){ |
| | | if(!$this->checkTableName($tablename)){ |
| | | |
| | | return false; |
| | | return FALSE; |
| | | } |
| | | |
| | | if(empty($where) || empty($value)){ |
| | | return false; |
| | | return FALSE; |
| | | } |
| | | |
| | | $SQL = "UPDATE `" . $this->def . $tablename . "` SET $value ".$where; |
| | |
| | | function DB_delete_all($tablename, $where, $limit = 'limit 1',$pecial='', $norecycle = ''){ |
| | | if(!$this->checkTableName($tablename)){ |
| | | |
| | | return false; |
| | | return FALSE; |
| | | } |
| | | if(empty($where)){ |
| | | return false; |
| | | return FALSE; |
| | | } |
| | | if($pecial!=$tablename){ |
| | | //快速创建简历保存数据不进入回收站 |
| | |
| | | $this->db->query("set `sql_mode`=''"); |
| | | return $this->db->query($SQL); |
| | | } |
| | | |
| | | /** |
| | | * @desc 删除数据库 |
| | | * @param $tablename 数据表名; |
| | | $where 删除数据表数据查询条件; |
| | | $limit 删除记录数 |
| | | $pecial 暂未发现使用 |
| | | $norecycle 1:不做回收站插入操作 |
| | | * $where 删除数据表数据查询条件; |
| | | * $limit 删除记录数 |
| | | * $pecial 暂未发现使用 |
| | | * $norecycle 1:不做回收站插入操作 |
| | | */ |
| | | function delete_all($tablename, $where = array(), $limit = 'limit 1', $special='', $norecycle = '') |
| | | { |
| | | function delete_all($tablename, $where = array(), $limit = 'limit 1', $special = '', $norecycle = '') { |
| | | |
| | | if(!$this->checkTableName($tablename)){ |
| | | |
| | | return false; |
| | | return FALSE; |
| | | } |
| | | include(PLUS_PATH.'dbstruct.cache.php'); |
| | | |
| | |
| | | |
| | | }else{ |
| | | |
| | | return false; |
| | | return FALSE; |
| | | } |
| | | |
| | | $this->db->query("set `sql_mode`=''"); |
| | |
| | | * @param $where |
| | | * @return bool |
| | | */ |
| | | function insert_recycle($tablename, $where) |
| | | { |
| | | function insert_recycle($tablename, $where) { |
| | | |
| | | if (!$this->checkTableName($tablename)) { |
| | | |
| | | return false; |
| | | return FALSE; |
| | | } |
| | | //回收站同一次操作生成数据MD5用作识别同一次操作的标识符 |
| | | if (!$this->__isset('recyclemd5')) { |
| | |
| | | /** |
| | | * 自定义SQL执行 便于多表联合、left join等组合查询语句 |
| | | */ |
| | | function DB_query_all($sql, $type = 'one') |
| | | { |
| | | function DB_query_all($sql, $type = 'one') { |
| | | |
| | | $this->db->query("set sql_mode=''"); |
| | | |
| | |
| | | } |
| | | return $return; |
| | | } |
| | | |
| | | /** |
| | | * 通用单条查询$tablename,$where = 1, $select="*" |
| | | |
| | | */ |
| | | function DB_select_once($tablename, $where = 1, $select = "*",$special='') { |
| | | |
| | | if(!$this->checkTableName($tablename)){ |
| | | |
| | | return false; |
| | | return FALSE; |
| | | } |
| | | |
| | | $cachename=$tablename.$where; |
| | |
| | | $where = $this->site_fetchsql($where,$tablename); |
| | | } |
| | | $SQL = 'SELECT '.$select.' FROM ' . $this->def . $tablename; |
| | | if($where) |
| | | { |
| | | if ($where) { |
| | | $SQL .= ' WHERE '.$where; |
| | | } |
| | | $SQL .= ' LIMIT 1'; |
| | |
| | | } |
| | | return $return; |
| | | } |
| | | |
| | | //新单条查询 |
| | | function select_once($tablename, $where = array(), $select = "*",$special='') { |
| | | |
| | | if(!$this->checkTableName($tablename)){ |
| | | |
| | | return false; |
| | | return FALSE; |
| | | } |
| | | |
| | | if($this->siteadmindir && $special==''){ |
| | |
| | | return $return; |
| | | } |
| | | |
| | | function member_log($content,$opera='',$type='',$uid=null,$usertype=null){//会员日志 |
| | | function member_log($content, $opera = '', $type = '', $uid = NULL, $usertype = NULL) {//会员日志 |
| | | if(!$uid && !$usertype){ |
| | | $uid = intval($_COOKIE['uid']); |
| | | $usertype = intval($_COOKIE['usertype']); |
| | |
| | | $this->DB_insert_once("member_log",$value); |
| | | } |
| | | } |
| | | |
| | | function FormatOptions($Options){ |
| | | if(!is_array($Options)){return array('field'=>'*','where'=>'');} |
| | | if (!is_array($Options)) { |
| | | return array('field' => '*', 'where' => ''); |
| | | } |
| | | $WhereStr=''; |
| | | if($Options['field']){ |
| | | $Field=$Options['field']; |
| | |
| | | } |
| | | return array('field'=>$Field,'order'=>$WhereStr,"special"=>$special); |
| | | } |
| | | |
| | | function FormatWhere($Where){ |
| | | $WhereStr='1'; |
| | | foreach($Where as $k=>$v){ |
| | |
| | | $position = strpos($k,'<>'); |
| | | $fieldName = trim(substr($k,0,$position)); |
| | | $WhereStr .=' and `'.$fieldName.'` <> \''.$v.'\''; |
| | | } |
| | | elseif(strpos($k,'<') > 0){ |
| | | } elseif (strpos($k, '<') > 0) { |
| | | $position = strpos($k,'<'); |
| | | $fieldName = trim(substr($k,0,$position)); |
| | | $WhereStr .=' and `'.$fieldName.'` < \''.$v.'\''; |
| | | } |
| | | elseif(strpos($k,'>') > 0){ |
| | | } elseif (strpos($k, '>') > 0) { |
| | | $position = strpos($k,'>'); |
| | | $fieldName = trim(substr($k,0,$position)); |
| | | $WhereStr .=' and `'.$fieldName.'` > \''.$v.'\''; |
| | | } |
| | | else{ |
| | | } else { |
| | | $WhereStr .=' and `'.$k.'`=\''.$v.'\''; |
| | | } |
| | | } |
| | | } |
| | | return $WhereStr; |
| | | } |
| | | |
| | | function FormatValues($Values){ |
| | | $ValuesStr=''; |
| | | foreach($Values as $k=>$v){ |
| | |
| | | function RemindDeal($TableName,$Values=array(),$Where=array()){ |
| | | if(!$this->checkTableName($TableName)){ |
| | | |
| | | return false; |
| | | return FALSE; |
| | | } |
| | | $ValuesStr = $this->FormatValues($Values); |
| | | $WhereStr = $this->FormatWhere($Where); |
| | | $this->DB_update_all($TableName,$ValuesStr,$WhereStr); |
| | | } |
| | | |
| | | function site_fetchsql($Where,$TableName,$SplitChar=' and '){ |
| | | if(!$this->checkTableName($TableName)){ |
| | | |
| | | return false; |
| | | return FALSE; |
| | | } |
| | | if(in_array($TableName,$this->sitetable)){ |
| | | if(is_array($Where)&&is_numeric($this->config['did'])){ |
| | |
| | | function get_page($table,$where='',$pageurl='',$limit=20,$field='*',$rowsname='rows'){ |
| | | if(!$this->checkTableName($table)){ |
| | | |
| | | return false; |
| | | return FALSE; |
| | | } |
| | | $rows=array(); |
| | | $page=$_GET['page']<1?1:$_GET['page']; |
| | |
| | | $num=$this->DB_select_num($table,$where); |
| | | if($num>$limit){ |
| | | $pages=ceil($num/$limit); |
| | | $pagenav=Page($page,$num,$limit,$pageurl,$notpl=false,null); |
| | | $pagenav = Page($page, $num, $limit, $pageurl, $notpl = FALSE, NULL); |
| | | } |
| | | $rows=$this->DB_select_all($table,$where.' limit '.$ststrsql.','.$limit,$field); |
| | | return array('total'=>$num,'pagenav'=>$pagenav,$rowsname=>$rows); |
| | | } |
| | | |
| | | function fetch_assoc(){ |
| | | return $this->db->fetch_assoc(); |
| | | } |
| | | |
| | | function checkTableName($table){ |
| | | |
| | | if (preg_match('/^[_a-z]{2,30}$/i',$table)){ |
| | | return true; |
| | | return TRUE; |
| | | }else { |
| | | return false; |
| | | return FALSE; |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | if(!empty($where['limit'])){ |
| | | |
| | | if(is_array($where['limit'])) |
| | | { |
| | | if (is_array($where['limit'])) { |
| | | |
| | | $limit = ' LIMIT '.(int)$where['limit'][0].','.(int)$where['limit'][1]; |
| | | |
| | |
| | | |
| | | if(!empty($where['orderby'])){ |
| | | |
| | | if(is_array($where['orderby'])) |
| | | { |
| | | if (is_array($where['orderby'])) { |
| | | |
| | | $orderby = ' ORDER BY '; |
| | | |
| | | foreach($where['orderby'] as $key=>$value){ |
| | | |
| | | if($key>0) |
| | | { |
| | | if ($key > 0) { |
| | | $orderby .= ','; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | } elseif (stripos($where['orderby'], 'CASE WHEN') !== false) |
| | | { |
| | | } elseif (stripos($where['orderby'], 'CASE WHEN') !== FALSE) { |
| | | //CASE THEN END 条件排序 |
| | | |
| | | $orderby = ' ORDER BY '.$where['orderby']; |
| | |
| | | //PHPYUNBTWSTART_A PHPYUNBTWEND_A PHPYUNBTWSTART_B PHPYUNBTWEND_B 这种可以组成多个() |
| | | // PHPYUNBTWSTART_A_DOUBLE、PHPYUNBTWEND_B_DOUBLE 考虑有需要多重括号的方式,增加此种写法 |
| | | //考虑到部分需要使用()执行优先级条件查询判断的情况 |
| | | if(strpos($key, 'PHPYUNBTWSTART') !== false){ |
| | | if (strpos($key, 'PHPYUNBTWSTART') !== FALSE) { |
| | | |
| | | if($whereNew!='') |
| | | { |
| | | if ($whereNew != '') { |
| | | $btwAndOr = ($value=='OR' || $value == 'or') ?' OR ':' AND '; |
| | | }else{ |
| | | $btwAndOr = ''; |
| | |
| | | |
| | | $whereNew .= $btwAndOr.'('; |
| | | // 带_DOUBLE为需要一个多的开始括号情况 |
| | | if(strpos($key, '_DOUBLE') !== false){ |
| | | if (strpos($key, '_DOUBLE') !== FALSE) { |
| | | $whereNew .= '('; |
| | | } |
| | | //标识符 用于判断是否是()内首项条件 非首项条件 必须使用 AND/OR 连接 |
| | | $btwStr = 1; |
| | | |
| | | }elseif(strpos($key, 'PHPYUNBTWEND') !== false){ |
| | | } elseif (strpos($key, 'PHPYUNBTWEND') !== FALSE) { |
| | | |
| | | $whereNew .= ')'; |
| | | // 带_DOUBLE为需要一个多的结束括号情况 |
| | | if(strpos($key, '_DOUBLE') !== false){ |
| | | if (strpos($key, '_DOUBLE') !== FALSE) { |
| | | $whereNew .= ')'; |
| | | } |
| | | //取消标识符 |
| | |
| | | }else{ |
| | | |
| | | //where格式不为纯字符串,则按照操作符函数进行处理 |
| | | if(!empty($value) && is_array($value)) |
| | | { |
| | | if (!empty($value) && is_array($value)) { |
| | | |
| | | //同一个字段 多项条件组合 |
| | | if(is_array($value[0])){ |
| | | |
| | | foreach($value as $sonv){ |
| | | |
| | | if($whereNew!='' && $btwStr != 1) |
| | | { |
| | | if ($whereNew != '' && $btwStr != 1) { |
| | | |
| | | $whereNew .= ($sonv[2] == 'OR' || $sonv[2] == 'or') ? ' OR ' : ' AND '; |
| | | } |
| | |
| | | } |
| | | |
| | | }else{ |
| | | if($whereNew!='' && $btwStr != 1) |
| | | { |
| | | if ($whereNew != '' && $btwStr != 1) { |
| | | $whereNew .= (isset($value[2]) && ($value[2] == 'OR' || $value[2] == 'or')) ? ' OR ' : ' AND '; |
| | | } |
| | | //根据value[0] 判断SQL操作符 并进行组合SQL语句 |
| | |
| | | |
| | | //首项条件 排除AND连接符 |
| | | |
| | | if($whereNew!='' && $btwStr != 1) |
| | | { |
| | | if ($whereNew != '' && $btwStr != 1) { |
| | | $whereNew .=' AND '; |
| | | } |
| | | //纯字符串格式默认为 = 操作符 |
| | |
| | | if(!isset($noFields)){ |
| | | |
| | | |
| | | if($whereNew) |
| | | { |
| | | if ($whereNew) { |
| | | $whereNew = ' WHERE '.$whereNew; |
| | | |
| | | } |
| | |
| | | |
| | | switch($dataV[0]){ |
| | | |
| | | case 'notin' : $sqlString = "`$daraKey` not in (".$this->db->escape_string($dataV[1]).")"; |
| | | case 'notin' : |
| | | $sqlString = "`$daraKey` not in (" . $this->db->escape_string($dataV[1]) . ")"; |
| | | break; |
| | | |
| | | case 'in' : $sqlString = "`$daraKey` in (".$dataV[1].")"; |
| | | case 'in' : |
| | | $sqlString = "`$daraKey` in (" . $dataV[1] . ")"; |
| | | break; |
| | | |
| | | case 'isnull' : $sqlString = "`$daraKey` is null"; |
| | | case 'isnull' : |
| | | $sqlString = "`$daraKey` is null"; |
| | | break; |
| | | |
| | | case 'notnull' : $sqlString = "`$daraKey` is not null"; |
| | | case 'notnull' : |
| | | $sqlString = "`$daraKey` is not null"; |
| | | break; |
| | | |
| | | case 'like' : $sqlString = "`$daraKey` LIKE ('%".$this->db->escape_string($dataV[1])."%')"; |
| | | case 'like' : |
| | | $sqlString = "`$daraKey` LIKE ('%" . $this->db->escape_string($dataV[1]) . "%')"; |
| | | break; |
| | | |
| | | case 'findin' : $sqlString = "FIND_IN_SET('".$this->db->escape_string($dataV[1])."',`$daraKey`)"; |
| | | case 'findin' : |
| | | $sqlString = "FIND_IN_SET('" . $this->db->escape_string($dataV[1]) . "',`$daraKey`)"; |
| | | break; |
| | | |
| | | case 'between' : $betweens = explode(',', $dataV[1]);$sqlString = "$daraKey between $betweens[0] AND $betweens[1]"; |
| | | case 'between' : |
| | | $betweens = explode(',', $dataV[1]); |
| | | $sqlString = "$daraKey between $betweens[0] AND $betweens[1]"; |
| | | break; |
| | | |
| | | case 'unixtime' : $sqlString = "UNIX_TIMESTAMP(`$daraKey`) ".$this->db->escape_string($dataV[1])." '$dataV[2]'"; |
| | | case 'unixtime' : |
| | | $sqlString = "UNIX_TIMESTAMP(`$daraKey`) " . $this->db->escape_string($dataV[1]) . " '$dataV[2]'"; |
| | | break; |
| | | |
| | | case 'like%' : $sqlString = "`$daraKey` LIKE ('".$this->db->escape_string($dataV[1])."%')"; |
| | | case 'like%' : |
| | | $sqlString = "`$daraKey` LIKE ('" . $this->db->escape_string($dataV[1]) . "%')"; |
| | | break; |
| | | |
| | | case 'dateformat': $sqlString = "date_format(`$daraKey`,'".$dataV[1]."')=date_format(now(),'".$this->db->escape_string($dataV[1])."')"; |
| | | case 'dateformat': |
| | | $sqlString = "date_format(`$daraKey`,'" . $dataV[1] . "')=date_format(now(),'" . $this->db->escape_string($dataV[1]) . "')"; |
| | | break; |
| | | // 字符串型的in |
| | | case 'in_s' : $sqlString = "`$daraKey` in ('".$dataV[1]."')"; |
| | | case 'in_s' : |
| | | $sqlString = "`$daraKey` in ('" . $dataV[1] . "')"; |
| | | break; |
| | | // 处理值匹配 |
| | | case 'regexp' : $sqlString = "(`$daraKey` REGEXP '".$dataV[1]."')=0"; |
| | | case 'regexp' : |
| | | $sqlString = "(`$daraKey` REGEXP '" . $dataV[1] . "')=0"; |
| | | break; |
| | | default : |
| | | // 传入字段中包含sql函数的,两边不需要加` |
| | |
| | | return $sqlString; |
| | | |
| | | } |
| | | |
| | | function uc_open(){ |
| | | include APP_PATH.'data/api/uc/config.inc.php'; |
| | | include APP_PATH.'/api/uc/include/db_mysql.class.php'; |
| | |
| | | return $ucinfo; |
| | | } |
| | | } |
| | | |
| | | ?> |