Welcome Guest, Not a member yet? Register   Sign In
Display SQL Query generated
#1

[eluser]Alex Jurado[/eluser]
How I can see the query that is generated from ...
Code:
$ci->db->select('id,name,token',FALSE)->from('users')->where(array('id'=>1,'status'=>true));

I need to create a function to get the SQL query, I mean
Code:
SELECT id,name,token FROM users WHERE id = 1 AND status = TRUE;
#2

[eluser]thisischris[/eluser]
Use $this->db->_compile_select().
#3

[eluser]Alex Jurado[/eluser]
Thanks, but get this error when running,
Code:
Fatal error: Call to protected method CI_DB_active_record::_compile_select() from context 'CI_Loader' ...

But when I run this, if it works,
Code:
print "SQL Query: ".$this->db->last_query();

Thanks for your help
#4

[eluser]thisischris[/eluser]
Is this within a library?

I just noticed your using $ci, in which case I would use $ci->db->_compile_select();
#5

[eluser]Alex Jurado[/eluser]
Do not think that's the problem, because I use $this
#6

[eluser]tpetrone[/eluser]
perhaps this?

Code:
echo $CI->db->last_query();
#7

[eluser]Alex Jurado[/eluser]
Yes,
[quote author="Alex Jurado" date="1343658610"]..., if it works,
Code:
print "SQL Query: ".$this->db->last_query();

Thanks for your help[/quote]
#8

[eluser]CroNiX[/eluser]
Shouldn't "true" be quoted in your where()? It's a string.




Theme © iAndrew 2016 - Forum software by © MyBB