CodeIgniter Forums
MySQLi delete in multiply tables - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: Issues (https://forum.codeigniter.com/forumdisplay.php?fid=19)
+--- Thread: MySQLi delete in multiply tables (/showthread.php?tid=61774)

Pages: 1 2


MySQLi delete in multiply tables - xmod - 05-15-2015

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


RE: MySQLi delete in multiply tables - gadelat - 05-16-2015

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


RE: MySQLi delete in multiply tables - xmod - 05-16-2015

(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. 


RE: MySQLi delete in multiply tables - CroNiX - 05-16-2015

(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.


RE: MySQLi delete in multiply tables - xmod - 05-17-2015

(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?


RE: MySQLi delete in multiply tables - gadelat - 05-17-2015

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.


RE: MySQLi delete in multiply tables - xmod - 05-17-2015

Where I can write about this bug to developers?


RE: MySQLi delete in multiply tables - CroNiX - 05-17-2015

(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


RE: MySQLi delete in multiply tables - Narf - 05-18-2015

It's not a bug, you have to pass the WHERE clause to delete() when you want to delete from multiple tables ...


RE: MySQLi delete in multiply tables - CroNiX - 05-18-2015

@Narf maybe the userguide needs updating then because what he had is exactly what it shows:
http://www.codeigniter.com/user_guide/database/query_builder.html#deleting-data
Code:
$tables = array('table1', 'table2', 'table3');
$this->db->where('id', '5');
$this->db->delete($tables);