delete() public method

Compiles a delete string and runs the query
public delete ( $table = '', $where = '', $limit = NULL, $reset_data = TRUE ) : object
return object
Esempio n. 1
0
 /**
  * Delete record(s) from this table, optionally extending by specifying a $Join to
  * delete adjoining data from both
  *
  * @param ifx_Model $JoinObject
  * @param mixed $JoinType
  *
  * @return bool
  */
 public final function delete(ifx_Model $JoinObject = null, $JoinType = 'INNER')
 {
     if (!empty($JoinObject) and is_a($JoinObject, get_class())) {
         //Generate the join
         $this->_forge_join($JoinObject, $JoinType);
         //Generate the query
         $SQL = 'DELETE ' . $JoinObject->_table() . ', ' . $this->_table() . ' FROM ' . $this->_forged_join();
         //If this object was loaded, limit by this record
         if ($this->is_loaded()) {
             $this->db->where($this->_table() . '.' . $this->_id(), $this->id());
         }
         //If the join object was loaded, limit the query by the loaded record
         if ($JoinObject->is_loaded()) {
             $this->db->where($JoinObject->_table() . '.' . $JoinObject->_id(), $JoinObject->id());
         }
         //Get the WHERE portion from CI_DB_AR
         $Where = implode(' ', $this->db->ar_where);
         $this->db->ar_where = array();
         //Join the WHERE, if any
         $SQL .= !empty($Where) ? ' WHERE ' . $Where : '';
         //Run the query
         $this->db->query($SQL);
         //Reset the forged table for next time
         $this->_clear_forged_join();
     } elseif ($this->is_loaded()) {
         //We only allow deletes for a loaded record, to avoid whole table deletes
         $this->db->where($this->_id(), $this->id());
         $this->db->delete($this->_table());
     }
     if ($this->db->affected_rows() >= 1) {
         $this->_data = array();
         return true;
     }
     return false;
 }
Esempio n. 2
0
 /**
  * 删除数据
  * @param array|string $where 条件
  * @param int $limit 删除数量限制,默认不限制
  * @return int $delete_count 删除的记录数
  */
 public function delete($where, $limit = NULL)
 {
     if (!is_null($limit) && is_numeric($limit)) {
         $this->where($where);
         if (is_numeric($limit)) {
             $this->db->limit($limit);
         }
         $this->db->delete($this->_name);
         return $this->db->affected_rows();
     }
     $this->db->delete($this->_name, $where);
     return $this->db->affected_rows();
 }