A Simple DELETE
Deleting rows from a table is very much like a SELECT query:
// Select the table
$table = db('mytable');
// Query the database
$table->delete()
->where('user','=','Evan')
->execute();
The above is the same as the following SQL:
DELETE FROM `mytable` WHERE `user`='Evan'
Because the above example is really simple it can be done shorthand:
// Select the table
$table = db('mytable');
// Query the database
$table->delete('user','=','Evan');
A More Complex Example
We can add multiple WHERE conditions to our query easily:
// Select the table
$table = db('mytable');
// Query the database
$table->delete()
->where('user','=','Evan')
->clause('OR')
->where('id','>=',25)
->execute();
DELETE FROM `mytable` WHERE `user`='Evan' OR `id`>='25'
© 2008 - 2010 Evan Byrne