CI_DB_query_builder::delete PHP Method

delete() public method

Compiles a delete string and runs the query
public delete ( $table = '', $where = '', $limit = NULL, $reset_data = TRUE ) : mixed
return mixed
    public function delete($table = '', $where = '', $limit = NULL, $reset_data = TRUE)
    {
        // Combine any cached components with the current statements
        $this->_merge_cache();
        if ($table === '') {
            if (!isset($this->qb_from[0])) {
                return $this->db_debug ? $this->display_error('db_must_set_table') : FALSE;
            }
            $table = $this->qb_from[0];
        } elseif (is_array($table)) {
            empty($where) && ($reset_data = FALSE);
            foreach ($table as $single_table) {
                $this->delete($single_table, $where, $limit, $reset_data);
            }
            return;
        } else {
            $table = $this->protect_identifiers($table, TRUE, NULL, FALSE);
        }
        if ($where !== '') {
            $this->where($where);
        }
        if (!empty($limit)) {
            $this->limit($limit);
        }
        if (count($this->qb_where) === 0) {
            return $this->db_debug ? $this->display_error('db_del_must_use_where') : FALSE;
        }
        $sql = $this->_delete($table);
        if ($reset_data) {
            $this->_reset_write();
        }
        return $this->return_delete_sql === TRUE ? $sql : $this->query($sql);
    }

Usage Example

Exemplo n.º 1
0
 public function delete($id)
 {
     return $this->db->delete($this->table, ['id' => $id]);
 }