Delete Query in PHP Codeigniter Framework

In this Codeigniter delete query tutorial – we would love to share with you how to delete a single or multiple records into database.

In this codeigniter tutorial you will learn how to empty and truncate database tables using codeigniter empty or truncate() method.

Codeigniter Delete Query

Contents

  • delete()
  • empty_table()
  • truncate()

delete() method

The Codeigniter Delete function is used to delete the one or more row data from database table.

syntax

$this->db->delete()
$this->db->delete('users', array('id' => $id)); 

Produce :

//DELETE FROM users WHERE id = $id

empty_table () Method

Syntax 

$this->db->empty_table('table_name');
$this->db->empty_table('users'); 
// DELETE FROM users

truncate() method

The truncate() method of codeigniter is used to remove all records from a database table. It performs the same function as a DELETE statement without a WHERE clause.

Syntax

$this->db->truncate('table_name');
$this->db->truncate('users'); 
// TRUNCATE table users;

Be First to Comment

Leave a Reply

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