0

Currently working on a small project with a few different database functions. I am trying to figure out a way to get the compiled Codeigniter WHERE statement.

// Database GET function
function dbGetRow($id, $field)
{
    $this->db->select($field)->from('friends');
    $query = $this->db->get();
    return $query->row_array();
}

// Calling the function
$this->db->where('id', 2);
$value = parent::dbGetRow(null 'id');

What i am trying to figure out is how to get the compiled WHERE statement inside of the dbGetRow() function before performing the query.

sam
  • 5
  • 1
  • 6
  • 1
    https://stackoverflow.com/questions/6142099/how-to-print-sql-statement-in-codeigniter-model – Felippe Duarte Jul 16 '18 at 18:57
  • 1
    Does the following help? - `echo $this->db->get_compiled_select();` – Simon K Jul 16 '18 at 19:01
  • i am already aware of $this->db->get_compiled_select(); however this does produces SELECT * 'statement here'; i was hoping to get just the statement without SELECT *, but i guess i will just strip replace that. – sam Jul 16 '18 at 19:03

1 Answers1

0

Got this working.

the only solution is to use $this->db->get_compiled_select();

private function hasInlineQuery()
{
    $string = $this->db->get_compiled_select();
    $string = str_ireplace('SELECT *', '', $string);

    return $string ? true : false;
}
sam
  • 5
  • 1
  • 6