Welcome Guest, Not a member yet? Register   Sign In
how can i see the actual query generated by AR?
#1

[eluser]mmiranda[/eluser]
Hi, i have a very strange problem with a mssql 2005 server, its just a simple query to a table (using flexigrid helper):


$table_name = "billing_200809";

//Build contents query
$this->db->select('timeOfBilling,credit,ctxt_nocall_login,tariffitem')->from($table_name);
$this->CI->flexigrid->build_query();
$return['records'] = $this->db->get();

//Build count query
$this->db->select('count(timeOfBilling) as record_count')->from($table_name);
$this->CI->flexigrid->build_query(FALSE);
$record_count = $this->db->get();
$row = $record_count->row();
$return['record_count'] = $row->record_count;

In the log i got:

ERROR - 2008-10-11 15:07:44 --&gt; Severity: Warning --&gt; mssql_query() [<a href='function.mssql-query'>function.mssql-query</a>]: message: Incorrect syntax near 'billing_200809'. (severity 15)

ERROR - 2008-10-11 15:07:44 --&gt; Severity: Warning --&gt; mssql_query() [<a href='function.mssql-query'>function.mssql-query</a>]: Query failed

How can i see what is wrong with the querys?
$log_treshold is at 4.
#2

[eluser]Sumon[/eluser]
Why not use CI profiller to view what the things are going under the hood.
#3

[eluser]Mirage[/eluser]
Quote:How can i see what is wrong with the querys?
$log_treshold is at 4.

To see the sql statement that was executed, turn on db_debug in the database config and/or add this line after your code to see it in the log:

Code:
//Build count query
$this->db->select(‘count(timeOfBilling) as record_count’)->from($table_name);
$this->CI->flexigrid->build_query(FALSE);

$record_count = $this->db->get();
log_message('debug', var_export($this->db->last_query(), true));

$row = $record_count->row();
$return[‘record_count’] = $row->record_count;

I'm also pretty sure that you're using the select method of the AR wrong. That method is supposed to take a list of fields, not a whole query. For doing a direct query you'd use $this->db->query($sql);


Cheers,
-m




Theme © iAndrew 2016 - Forum software by © MyBB