Welcome Guest, Not a member yet? Register   Sign In
Error deleting from sessions
#1

[eluser]stef25[/eluser]
Every now and then CI gives me the following error:

Code:
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 '`< 1338447923`' at line 2

DELETE FROM `ci_sessions` WHERE `last_activity` `< 1338447923`

Filename: libraries/Session.php

Line Number: 766

This syntax is wrong, there should be no backticks on the timestamp value. However this is coming out of the CI core and should be unrelated to my own code.

The error referes to this garbage collection snippet from the Session library:

Code:
$expire = $this->now - $this->sess_expiration;

   $this->CI->db->where("last_activity < {$expire}");
   $this->CI->db->delete($this->sess_table_name);

I started off this project with CI 3.0 dev, ditched it for 2.1.0 and copied my controllers, models, views, config files etc over from the 3.0 project in to the 2.0. Is it possible I get this error because of some remaining 3.0 code in a 2.1.0 project?


#2

[eluser]Aken[/eluser]
Any particular reason you ditched the 3.0 dev? Just out of curiosity.

So long as you replaced all the important system files (system folder, index.php), I'd assume it should be fine. This kind of bug would've been addressed FAST, and definitely wouldn't be in a production version of CI.

What database are you using?
#3

[eluser]stef25[/eluser]
3.0 was ditched because I was having problems getting my "homepage" (ie the base url) to point to the default controller using the htaccess file I normally use. I didn't investigate in depth.

I agree with you, this can't be a real CI bug. But since it's CI internal garbage collection and not "my" code that triggers this, I have no idea where to start looking for the cause. It's a brand new clean project. The error keeps coming back but when I F5 it disappears.

The DB is a normal MySQL one (don't have the exact version here)

EDIT: I'm using jamie rumbelow's My_Model, maybe the problem is there ...
#4

[eluser]Abel A.[/eluser]
query is wrong:

Code:
DELETE FROM `ci_sessions` WHERE `last_activity` < 1338447923

The tick is wrong.
#5

[eluser]CroNiX[/eluser]
Yeah, the where should be
Code:
$this->CI->db->where("last_activity <", $expire);
#6

[eluser]stef25[/eluser]
garbage collection in 2.1.0 (produces error)

Code:
$this->CI->db->where("last_activity < {$expire}");

garbage collection in 3.0

Code:
$this->CI->db->where('last_activity < '.$expire);

These snippets come from the github repo. Not sure why I'm the only one seeing this error, is there a difference in how the active record syntax is parsed or ... ?
#7

[eluser]Mark Croxton[/eluser]
I had the same problem. This was my solution:

https://gist.github.com/2923657
#8

[eluser]stef25[/eluser]
Thanks for the heads up.

I just discovered this query also creates faulty SQL

Code:
$this->db->where('language !=', 'NL');
$res = $this->db->get('translations')->result_array();




Theme © iAndrew 2016 - Forum software by © MyBB