Codeigniter delete query from Database

Today, We want to share with you Codeigniter delete query from Database.In this post we will show you deletes query in codeigniter with where condition, hear for Codeigniter Active Record: Insert, Select, Update, Deletes we will give you demo and example for implement.In this post, we will learn about Delete Query In Codeigniter Example Tutorial with an example.

Codeigniter delete query from Database

There are the Following The simple About where condition in codeigniter Full Information With Example and source code.

As I will cover this Post with live Working example to develop how to delete data from database in codeigniter using ajax, so the select query in codeigniter controller is used for this example is following below.

delete query in codeigniter
delete query in codeigniter

There are the Following the List of deletes/remove record in codeigniter methods:

  • $this->db->delete()
  • $this->db->empty_table()
  • $this->db->truncate()
  • Delete With Join

Using $this->db->delete()

$this->db->delete('tbl_patient', array('doctor_id' => $doctor_id)); 
//DELETE FROM tbl_patient WHERE doctor_id = $doctor_id

$this->db->where('doctor_id', $doctor_id);
$this->db->delete('tbl_patient');
//DELETE FROM tbl_patient WHERE doctor_id = $doctor_id

simple pass An array of Dataabse table names can be argument passed into delete() function if you would like to simple database table to deletes/remove data from multiple table.deletes query in codeigniter with where condition

Another must read:  Laravel delete foreign key Constraint Using Migration

List of all Google Adsense, VueJS, AngularJS, PHP, Laravel Examples.

$doctor_id=5;
$tables = array('doctor', 'staff', 'category');
$this->db->where('doctor_id', $doctor_id);
$this->db->delete($tables);

Using $this->db->empty_table()

$this->db->empty_table('tbl_patient'); 
// DELETES FROM tbl_patient

Using $this->db->truncate()

$this->db->from('tbl_patient'); 
$this->db->truncate(); 
(OR)
$this->db->truncate('tbl_patient'); 
// TRUNCATE table tbl_patient;

Delete With Join

$this->db->from("doctor");
$this->db->join("staff", "doctor.t1_doctor_id = staff.t2_doctor_id");
$this->db->where("staff.t2_doctor_id", $doctor_id);
$this->db->delete("doctor");

Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Codeigniters CRUD Active Record: Insert, Select, Update, Deletes Example.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Reply

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