protected function _set($key, $data, $group, $tenant_id, $expires = null) { if (empty($expires)) { $expires = $this->default_expires; } $data = $this->_serialize(array('data' => $data, 'expires' => time() + intval($expires))); $this->_delete($key, $group, $tenant_id); $r = $this->_db->insert($this->_table, array($this->_table . '.key' => $key, $this->_table . '.group' => $group, $this->_table . '.value' => $data, $this->_table . '.tenant_id' => $tenant_id)); return $this->_db->affected_rows() > 0; }
/** * The actual function used for updating or interting a record * * @return bool */ private final function _save_row() { //First run validation, and bail out if it fails if ($this->validate() == FALSE) { return FALSE; } $this->_set_row(); if ($this->_isnew) { $this->db->insert($this->_table()); $this->_data[$this->_id()] = $this->db->insert_id(); $Return = $this->id() != NULL; if ($Return == true) { $this->_isnew = false; $Record = new stdClass(); foreach ($this->_data as $K => $V) { $Record->{$K} = $V; } $this->_original_record = $Record; } return $Return; } else { $this->db->where($this->_id(), $this->id()); $this->db->update($this->_forged_join()); //Just in case a join has been forged $this->_clear_forged_join(); if ($this->_record_is_changed()) { return $this->db->affected_rows() > 0; } return true; } }
/** * 插入数据 * @param array $set 数据集合(key/value) * @return int $insert_id 如果插入的表有自动增长主键,则返回增长后的值,否则返回影响记录条数 */ public function insert(array $set) { $this->db->insert($this->_name, $set); $insert_id = $this->db->insert_id(); if ($insert_id <= 0) { return $this->db->affected_rows(); } else { return $insert_id; } }