Welcome Guest, Not a member yet? Register   Sign In
how to delete from multiple tables using QB
#1
Question 

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

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

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

You can't, and that's intentional.
Reply
#5

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

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

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




Theme © iAndrew 2016 - Forum software by © MyBB