CodeIgniter Forums

Full Version: MySQLi delete in multiply tables
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hi.

In this code

PHP Code:
$tables = array('tasks''task_time''task_favorites''task_subscribers'); 
 
$this->db->where('task_id'$task_id);
 
$this->db->delete($tables); 

I've got error

Code:
Deletes are not allowed unless they contain a "where" or "like" clause.

What's wrong?

CI version 3.0.1
I think it's clear enough. CI developers decided it's unsafe to use db->delete without where clause so they forbidden it. Better to use db->truncate anyway
(05-16-2015, 01:38 AM)gadelat Wrote: [ -> ]I think it's clear enough. CI developers decided it's unsafe to use db->delete without where clause so they forbidden it. Better to use db->truncate anyway

Yes, but I have where clause in my code. See 2nd line. 
(05-16-2015, 01:38 AM)gadelat Wrote: [ -> ]I think it's clear enough. CI developers decided it's unsafe to use db->delete without where clause so they forbidden it. Better to use db->truncate anyway
Did you look at his code? He has a "where" statement, and his code is almost identical to the example in the userguide, so it should work fine.
(05-16-2015, 04:01 PM)CroNiX Wrote: [ -> ]
(05-16-2015, 01:38 AM)gadelat Wrote: [ -> ]I think it's clear enough. CI developers decided it's unsafe to use db->delete without where clause so they forbidden it. Better to use db->truncate anyway
Did you look at his code? He has a "where" statement, and his code is almost identical to the example in the userguide, so it should work fine.

Yeah! Is it bug?
Ah sorry, somehow I did not see that. Well, this code definitely works. Maybe your installation is somehow messed up. Try to replace system folder again, if it does not help, you need to track the problem yourself.
Where I can write about this bug to developers?
(05-17-2015, 05:45 AM)xmod Wrote: [ -> ]Where I can write about this bug to developers?

In the issues for the github repo
https://github.com/bcit-ci/CodeIgniter/issues
It's not a bug, you have to pass the WHERE clause to delete() when you want to delete from multiple tables ...
@Narf maybe the userguide needs updating then because what he had is exactly what it shows:
http://www.codeigniter.com/user_guide/da...eting-data
Code:
$tables = array('table1', 'table2', 'table3');
$this->db->where('id', '5');
$this->db->delete($tables);
Pages: 1 2