Posted inphp / Codeigniter

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

$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.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

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

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype