Welcome Guest, Not a member yet? Register   Sign In
question about active records / db
#1

[eluser]Unknown[/eluser]
Hi.

I want to know how do I get the sql string what was generated by active records class.
For example, I have this code:
$this->db->select('*');
$this->db->where('id',3);
$this->db->where('name','test');
$this->db->from('my_table');

$query=$this->db->get();

The class generates something like
"select * from my_table where id=3 and name='test'"

How do I get this sql string ?


Thanks
#2

[eluser]alexsancho[/eluser]
You've got two options,

- Enabling profiler
Code:
$this->output->enable_profiler = TRUE;

- Using active record last_query

Code:
$this->db->last_query()


hopes this helps
#3

[eluser]Alex007[/eluser]
Both of these methods will work IF the query has been run.

If you want to compile the SQL string without running it, try this:
Code:
$sql = $this->db->_compile_select();




Theme © iAndrew 2016 - Forum software by © MyBB