Welcome Guest, Not a member yet? Register   Sign In
MySQLi delete in multiply tables
#13

(05-18-2015, 07:39 AM)CroNiX Wrote: @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);

(05-20-2015, 08:16 AM)mwhitney Wrote:
(05-18-2015, 12:47 AM)Narf Wrote: It's not a bug, you have to pass the WHERE clause to delete() when you want to delete from multiple tables ...

This definitely needs to be clarified in the documentation, as this would also be the case with $limit/$this->db->limit(), unless you set the last argument ($reset_data) to FALSE.

Of course, if you set the last argument to FALSE, you have to take care to call $this->db->reset_query() as needed before performing other database operations.

At first, I thought it would be relatively simple to "fix" the behavior of the delete() method for arrays, but there are a lot of potential issues hiding in there with those last three arguments.

[Edit]
...and just to make the last point clear, if you do set the last argument to FALSE while passing the $where and/or $limit clauses, it will call where() and limit() before calling _delete() on each table in the array, even though the where and limit clauses aren't reset from the calls for the previous table(s).

I didn't realize there was such an example in the documentation ... that may indeed make it a bug. The potential issues that you see, together with other factors (like not making it easy to delete from 10 tables by accident) are why I wouldn't consider this to be a good feature. Will have to look into it again, I guess.
Reply


Messages In This Thread
MySQLi delete in multiply tables - by xmod - 05-15-2015, 08:02 AM
RE: MySQLi delete in multiply tables - by gadelat - 05-16-2015, 01:38 AM
RE: MySQLi delete in multiply tables - by xmod - 05-16-2015, 10:59 AM
RE: MySQLi delete in multiply tables - by CroNiX - 05-16-2015, 04:01 PM
RE: MySQLi delete in multiply tables - by xmod - 05-17-2015, 01:08 AM
RE: MySQLi delete in multiply tables - by gadelat - 05-17-2015, 05:25 AM
RE: MySQLi delete in multiply tables - by xmod - 05-17-2015, 05:45 AM
RE: MySQLi delete in multiply tables - by CroNiX - 05-17-2015, 09:55 AM
RE: MySQLi delete in multiply tables - by Narf - 05-18-2015, 12:47 AM
RE: MySQLi delete in multiply tables - by CroNiX - 05-18-2015, 07:39 AM
RE: MySQLi delete in multiply tables - by Athov - 05-18-2015, 07:53 AM
RE: MySQLi delete in multiply tables - by Narf - 05-20-2015, 03:20 PM
RE: MySQLi delete in multiply tables - by Narf - 07-02-2015, 01:51 AM



Theme © iAndrew 2016 - Forum software by © MyBB