Beispiel #1
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;
     }
 }
Beispiel #2
0
 /**
  * 插入数据
  * @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;
     }
 }