CodeIgniter Forums
how to delete from multiple tables using QB - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: how to delete from multiple tables using QB (/showthread.php?tid=64936)



how to delete from multiple tables using QB - Tecvid - 04-13-2016

hi everyone! how can rewrite the code below using pure QB without extending Query Builder Class?

PHP Code:
public function deny_email($user_id)
{
    
$sql 'DELETE  `users`, `users_temp`, `user_settings`
            FROM    `users`, `users_temp`, `user_settings`
            WHERE   `users`        .`user_id`       = '
.$user_id.'
            AND     `users_temp`   .`utemp_user_id` = '
.$user_id.'
            AND     `user_settings`.`uset_user_id`  = '
.$user_id;

    return 
$this->db->query($sql);


i have tried smth like this ->delete('user, users_temp, user_settings') n like this ->delete('user', 'users_temp', 'user_settings'), but the 1st query gives an error, the 2nd one works just for the first given table, i have also tried to pass 'em using array, but caught an error

thanks in advance!


RE: how to delete from multiple tables using QB - Tpojka - 04-13-2016

Try with:

PHP Code:
"DELETE users, users_temp, user_settings FROM users INNER JOIN users_temp ON users.user_id = users_temp.utemp_user_id INNER JOIN user_settings
ON users.user_id = user_settings.uset_user_id WHERE users.user_id = 
$user_id"

Not sure if it will work, you have to test it though. MySQL official docs say next.


RE: how to delete from multiple tables using QB - Tecvid - 04-13-2016

(04-13-2016, 07:41 AM)Tpojka Wrote: Try with:

PHP Code:
"DELETE users, users_temp, user_settings FROM users INNER JOIN users_temp ON users.user_id = users_temp.utemp_user_id INNER JOIN user_settings
ON users.user_id = user_settings.uset_user_id WHERE users.user_id = 
$user_id"

Not sure if it will work, you have to test it though. MySQL official docs say next.

it seems u missunderstood me, my query is works, i have no problem with this, but i wonder if it possible to make it with query builder, without using native queries with query() method

anyway thanks for a reply Smile


RE: how to delete from multiple tables using QB - Narf - 04-13-2016

You can't, and that's intentional.


RE: how to delete from multiple tables using QB - Tecvid - 04-13-2016

(04-13-2016, 09:32 AM)Narf Wrote: You can't, and that's intentional.

why intentional? is it bad? o.O or just 4 security (or maybe 4 caution) reasons, but i think these should be care of developers who use this framework


RE: how to delete from multiple tables using QB - Narf - 04-13-2016

There's more to it than that, but enforcing "caution" is perhaps the shortest way to describe the reasons why, yes.

You are of course entitled to your opinion, but this one is set in stone.


RE: how to delete from multiple tables using QB - Tecvid - 04-13-2016

(04-13-2016, 11:00 AM)Narf Wrote: There's more to it than that, but enforcing "caution" is perhaps the shortest way to describe the reasons why, yes.

You are of course entitled to your opinion, but this one is set in stone.

clear, thanks Smile