I'm using CodeIgniter 3. I just need to know if there is a 'where' condition added to the query builder until now.
I'm calling a 'delete' function that deleted rows from database And it's possible to add a where condition before calling that function. Something like this:
public function delete()
{
// Here I need to know if where condition added to the db class
$this->db
->where('field', 1)
->delete('my_table');
}
public function main()
{
$this->db->where('field2', 2);
$this->delete();
}
I found a solution. The only thing I need to do is getting a select query and search for 'where' clause inside it:
public function delete()
{
// Here I need to know if where condition added to the db class
$sql = $this->db->get_compiled_select(NULL, FALSE);
$has_where = stripos($sql, 'where') !== FALSE;
// $has_where is TRUE if there is a where condition defined until now
$this->db
->where('field', 1)
->delete('my_table');
}
public function main()
{
$this->db->where('field2', 2);
$this->delete();
}