Reputation: 2042
My Query-
$shortlistpartners
is array
$this->db->delete('shortlist_partners');
$this->db->where('opp_id',$this->input->post('opp_id'));
$this->db->where_in('partner_id',$shortlistpartners);
Deletes are not allowed unless they contain a "where" or "like" clause. error is coming,tell me any solution.
Upvotes: 7
Views: 6898
Reputation: 5625
Actually, CI delete()
method returns no where or limit
error on:
From the Source Code:
if (count($this->ar_where) == 0 && count($this->ar_wherein) == 0 && count($this->ar_like) == 0)
{
if ($this->db_debug)
{
return $this->display_error('db_del_must_use_where');
}
return FALSE;
}
So I guess all you need to do is to swap your wheres with delete call:
$this->db->where('opp_id',$this->input->post('opp_id'));
$this->db->where_in('partner_id',$shortlistpartners);
$this->db->delete('shortlist_partners');
Upvotes: 3
Reputation: 4888
You have --safe-updates
enabled, which doesn't allow DELETE without WHERE
For beginners, a useful startup option is --safe-updates
(or --i-am-a-dummy, which has the same effect). It is helpful for cases when you might have issued a DELETE FROM tbl_name statement but forgotten the WHERE clause. Normally, such a statement deletes all rows from the table. With --safe-updates
, you can delete rows only by specifying the key values that identify them. This helps prevent accidents.
Have a look a MySQL Doc
The quick fix is to add SET SQL_SAFE_UPDATES=0; before your query :
SET SQL_SAFE_UPDATES=0;
OR use TRUNCATE TABLE_NAME;
if you need to delete all records from table.
Upvotes: 1