Delete records

Learn how to delete existing records

Deleting records is done by using the from and the delete methods.

// Delete all users

$result = $db->from('users')

Deleting a specific set of records is done by adding filters.

// Delete all users which don't have a description

$result = $db->from('users')
DELETE FROM `users` WHERE `description` IS NULL

You can also delete from multiple tables simultaneously by performing a join and passing to the delete method a list of tables as an array argument.

// Delete a specific user and all its orders

$result = $db->from('users')
             ->join('orders', function($join){
                $join->on('', 'orders.user_id');
             ->delete(array('users', 'orders'));
DELETE `users`, `orders` FROM `users`
    INNER JOIN `orders` ON `users`.`id` = `orders`.`user_id`
WHERE `users`.`id` = 2014