public function massign($data) { if (!is_array($data)) { return false; } $this->data = util::array_merge($this->data, $data); }
/** * can set params batch by method * @param array $data * @param enum $type = get / post * @return bool */ public static function setParams($data, $type = 'get') { self::_checkInit(); if (!is_array($data)) { return false; } if ($type == 'get') { $_GET = util::array_merge($_GET, $data); self::$_getData = util::array_merge(self::$_getData, self::_formatDeep($data)); } else { $_POST = util::array_merge($_POST, $data); self::$_postData = util::array_merge(self::$_postData, self::_formatDeep($data)); } }
public function count($key = '') { auto::isDebugMode() && ($_debugMicrotime = microtime(true)); $countKey = empty($key) ? '*' : $key; $where = $this->_getWhere(); $sql = $where['sql']; $sqlData = $where['data']; $values = array(); if (is_array($sqlData)) { $values = util::array_merge($values, $sqlData); } $sql = "SELECT COUNT({$countKey}) FROM " . $this->_table . $sql; $this->_lastQuery = array($sql, $values); $sth = $this->_getPdoByMethodName(__FUNCTION__)->prepare($sql); $res = $sth->execute($values); if ($res === false) { $this->_raiseError('count query failed~', exception_mysqlpdo::type_query_error); } $count = $sth->fetchColumn(); $this->_clearStat(); auto::isDebugMode() && auto::dqueue(__METHOD__, 'cost ' . (microtime(true) - $_debugMicrotime) . 's of query: ' . var_export($this->_lastQuery, true)); return $count; }
public function whereMatch($match = array(), $in = array(), $notIn = array(), $like = array(), $between = array()) { /** * where a=1 and b=2 and c in (123,34,3,5) and b not in (3,2,4) and x like '435%' and y between y1 and y2, group by a order by b desc limit 20 * * * array('match'=>array(), 'in'=>array(), 'like'=>array() ) * * @return string */ $sql = '1'; $whereData = array(); if ($match && is_array($match)) { foreach ($match as $k => $v) { $sql .= ' AND ' . $k . ' = ? '; $whereData[] = $v; } } if ($in && is_array($in)) { foreach ($in as $k => $v) { if (!is_array($v)) { continue; } $insteads = array_fill(0, count($v), '?'); $sql .= ' AND ' . $k . ' IN( ' . implode(',', $insteads) . ') '; $whereData = util::array_merge($whereData, $v); } } if ($notIn && is_array($notIn)) { foreach ($notIn as $k => $v) { if (!is_array($v)) { continue; } $insteads = array_fill(0, count($v), '?'); $sql .= ' AND ' . $k . ' NOT IN( ' . implode(',', $insteads) . ') '; $whereData = util::array_merge($whereData, $v); } } if ($like && is_array($like)) { foreach ($like as $k => $v) { $sql .= ' AND ' . $k . ' LIKE ? '; $whereData[] = $v; } } if ($between && is_array($between)) { foreach ($between as $k => $v) { $sql .= ' AND ( ' . $k . ' BETWEEN ? AND ? )'; $whereData[] = $v[0]; $whereData[] = $v[1]; } } $this->_sql['where'] = $sql; $this->_sql['whereData'] = $whereData; return $this; }