/** * 执行数据库更新操作,参数为主键ID,值$data,必须是键值对应的 * @param $id 主键ID * @param $data 数据 * @param $table 表名 * @param $where 其他字段 * @return $n SQL语句的返回值 */ public function update($id, $data, $table, $where = 'id') { if (func_num_args() < 3) { echo Error::info('SelectDB param error', 'Update must have 3 paramers ($id,$data,$table) !'); return false; } $this->db_apt->init(); $this->db_apt->from($table); $this->db_apt->where("{$where}='{$id}'"); $this->write_times += 1; return $this->db_apt->update($data); }
/** * 更新一组数据 * @param array $data 更新的数据 * @param array $params update的参数列表 * @return bool * @throws \Exception */ public function sets($data, $params) { if (empty($params)) { throw new \Exception("Model sets params is empty!"); } $selectdb = new SelectDB($this->db); $selectdb->from($this->table); $selectdb->put($params); return $selectdb->update($data); }