Codeigniter Delete Query Tutorial

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;

Recommended Tutorials

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

One reply to Codeigniter Delete Query Tutorial

  1. nice post

Leave a Reply

Your email address will not be published. Required fields are marked *