Welcome Guest, Not a member yet? Register   Sign In
MySQLi delete in multiply tables
#1
Bug 
(This post was last modified: 05-17-2015, 05:44 AM by xmod.)

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
Reply
#2

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
Reply
#3

(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. 
Reply
#4

(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.
Reply
#5

(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?
Reply
#6

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.
Reply
#7

Where I can write about this bug to developers?
Reply
#8

(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
Reply
#9

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

@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);
Reply




Theme © iAndrew 2016 - Forum software by © MyBB