Welcome Guest, Not a member yet? Register   Sign In
CI Database Error when Setting Timezone in MySQL
#1

[eluser]chuckleberry13[/eluser]
I'm getting an error running a particular query. If I copy and past the query into phpMyAdmin it runs fine, if I run it with CI I get a database error.

Here's the code

Code:
$sql = "SET time_zone = TIME_FORMAT(SEC_TO_TIME('".$offset."'),'%H:%i');
            SELECT YEAR(`timestamp`) AS year, WEEKOFYEAR(`timestamp`) AS week, DATE(`timestamp`) AS day, `user_id`, `list_id`, MIN(timestamp) as first_call, MAX(TIMESTAMP) as last_call, TIME_TO_SEC(TIMEDIFF(MAX( TIMESTAMP ), MIN(timestamp))) as total_time
            FROM (`".$this->transaction_table."`)
            WHERE `list_id` IN ('".implode("','",$list_ids)."')
            GROUP BY `day`, `list_id` ORDER BY `week`  DESC";
return $this->db->query($sql);

Here's the error
Code:
A Database Error Occurred

        
Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ';
            SELECT YEAR(`timestamp`) AS year, WEEKOFYEAR(`timestamp`) AS week, DATE(`ti' at line 1

SET time_zone = TIME_FORMAT(SEC_TO_TIME('-21600'),'%H:%i');
            SELECT YEAR(`timestamp`) AS year, WEEKOFYEAR(`timestamp`) AS week, DATE(`timestamp`) AS day, `user_id`, `list_id`, MIN(timestamp) as first_call, MAX(TIMESTAMP) as last_call, TIME_TO_SEC(TIMEDIFF(MAX( TIMESTAMP ), MIN(timestamp))) as total_time
            FROM (`call_transactions`)
            WHERE `list_id` IN ('5','54')
            GROUP BY `day`, `list_id` ORDER BY `week`  DESC

I've found that if I take out the SET time_zone line it will run in CI ok. But why would CI choke on this query, when if you run the query natively it runs fine? Any ideas?


Messages In This Thread
CI Database Error when Setting Timezone in MySQL - by El Forum - 10-28-2009, 07:13 PM
CI Database Error when Setting Timezone in MySQL - by El Forum - 10-28-2009, 08:10 PM
CI Database Error when Setting Timezone in MySQL - by El Forum - 10-28-2009, 09:43 PM
CI Database Error when Setting Timezone in MySQL - by El Forum - 10-28-2009, 10:05 PM
CI Database Error when Setting Timezone in MySQL - by El Forum - 10-29-2009, 11:34 AM
CI Database Error when Setting Timezone in MySQL - by El Forum - 10-29-2009, 11:35 AM



Theme © iAndrew 2016 - Forum software by © MyBB