I have sql query for delete multiple record from database
$sql="delete from users where id IN(4,5,6..)";
How to run this query in codeigniter
I have sql query for delete multiple record from database
$sql="delete from users where id IN(4,5,6..)";
How to run this query in codeigniter
Per the documents, you can use the query builder, or you can run a direct query on the database.
The query() function returns a database result object when “read” type queries are run, which you can use to show your results. When “write” type queries are run it simply returns TRUE or FALSE depending on success or failure. When retrieving data you will typically assign the query to your own variable, like this:
$query = $this->db->query('delete from users where id IN(4,5,6..)');
Or you can use the query builder class which allows you to do the following:
$this->db->where_in('id', array(4,5,6));
$this->db->delete('users');
Create a function in you model
function rowDelete($ids)
{
$this->db->where_in('id', $ids);
$this->db->delete('testimonials');
}
And call that in your controller
$this->your_model->rowDelete($ids) // $ids = array(4,5,6);
You can also execute query like this
$delete = "id IN('4','5','6')";
$this->db->where($delete);
$this->db->delete("user");
In this you can also execure your core query.