Welcome Guest, Not a member yet? Register   Sign In
Active Record SELECT bug?
#1

[eluser]Armorfist[/eluser]
EDIT:
Second parameter of Active Record SELECT function to FALSE solved it. Sorry for the wrong bug report!

Hello,

I have the following query:

Code:
$this->db->select('sess.session_id,sess.ip,sess.location,sess.login_date,users.username,users.id as user_id,TIMESTAMPDIFF('.$format.',NOW(),FROM_UNIXTIME(sess.timestamp)) as time_diff')->from($table_name);
$this->db->join($join_table_1, 'sess.user_id = users.id', 'left');
$return['records'] = $this->db->get();

When I run it, it retrieves this error:


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:
'`MINUTE`, NOW(), FROM_UNIXTIME(sess.timestamp)) as time_diff FROM (`login_sessio' at line 1



This is caused because for some reason active record adds `` to the MINUTE bit.
Here's the query ActiveRecord produces:
Code:
SELECT sess.session_id, sess.ip, sess.location, sess.login_date
, users.username, users.id as user_id,
TIMESTAMPDIFF(`MINUTE`, NOW(), FROM_UNIXTIME(sess.timestamp)) as time_diff
FROM (`login_sessions` sess)
LEFT JOIN `login_users` users ON sess.user_id = users.id

Here's how it should be:
Code:
SELECT sess.session_id, sess.ip, sess.location, sess.login_date
, users.username, users.id as user_id,
TIMESTAMPDIFF(MINUTE, NOW(), FROM_UNIXTIME(sess.timestamp)) as time_diff
FROM (`login_sessions` sess)
LEFT JOIN `login_users` users ON sess.user_id = users.id

Notice `MINUTE` instead of MINUTE

Any response will be appreciated.

Thanks,
Frederico

EDIT:
Second parameter of Active Record SELECT function to FALSE solved it. Sorry for the wrong bug report!


Messages In This Thread
Active Record SELECT bug? - by El Forum - 09-30-2008, 05:26 PM



Theme © iAndrew 2016 - Forum software by © MyBB