public function index(HttpRequest $request) { $this->setView("index"); $this->assign("title", "欢迎使用Herosphp"); $conditions = array('name' => 'xiaoming', '#address' => 'shenzhen'); $builder = MysqlQueryBuilder::buildConditions($conditions); die($builder); }
/** * @see Idb::count() */ public function count($table, $condition = null) { $sql = "SELECT count(*) as total FROM {$table}"; if ($condition != null) { $sql .= " WHERE " . MysqlQueryBuilder::buildConditions($condition); } $result = $this->excute($sql); $res = $result->fetch(PDO::FETCH_ASSOC); return $res['total']; }
/** * @see IModel::batchReduce() * @param string $field * @param int $offset * @param array|string $conditions * @return mixed|\PDOStatement */ public function batchReduce($field, $offset, $conditions) { $conditions = MysqlQueryBuilder::buildConditions($conditions); $update_str = "{$field}=REPLACE({$field}, '{$offset}', '')"; if (is_numeric($offset)) { $update_str = "{$field}={$field}-{$offset}"; } $query = "UPDATE {$this->table} SET {$update_str} WHERE {$conditions}"; return $this->db->excute($query); }