In this example tutorial, we would love to share how to delete a single or multiple records from a database using delete query.
Codeigniter Delete Query
Here are some built-in methods in CodeIgniter to delete data from database:
- delete()
- empty_table()
- truncate()
delete()
Delete function is used to delete one or more rows of data from a database table.
$this->db->delete('users', array('id' => $id));
Produce :
//DELETE FROM users WHERE id = $id
empty_table ()
empty_table() function delete all rows/records from a table.
$this->db->empty_table('users');
truncate()
The truncate() method of codeigniter removes all records from a database table. It performs the same function as a DELETE statement without a WHERE clause.
$this->db->truncate('users');
// TRUNCATE table users;
nice post