Take the 2-minute tour ×

I'm using database sessions and I keep seeing the following error in my log file.

2011-11-24 16:42:30 Warning: Warning (512): SQL Error: 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 'AS Session
WHERE Session.id = 'd1cc24fdacc4f7345fa1f2b4957d22eb'' at line 1 in [(path)/cake/libs/model/datasources/dbo_source.php, line 684]

I haven't had any complaints from my users yet but I assume they are seeing an error page or being logged out. Has anyone else had similar problems with database sessions in CakePHP?


I'm using CakePHP version 1.3.11.

The sessions table has over 2800 records in it and is defined as follows.

CREATE TABLE `cake_sessions` (
  `id` varchar(255) NOT NULL,
  `data` text,
  `expires` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
share|improve this question
That query appears to select an invalid (hashed) id. Which version of Cake is this? –  mensch Nov 25 '11 at 9:08
I'm using cake version 1.3.11. I didn't think it would matter so I changed a couple digits when I posted the error message. The actual hash was d1cc24fdacc4f7338fa1f2b4957d22eb. –  Lawrence Barsanti Nov 25 '11 at 10:13
What's the structure of your sessions table and is there any data present (just to be sure)? Cake apparently stores hashed strings in the id column of a sessions table, instead of integers. These errors tend to be a bit hard to debug as everything is done "automagically" in Cake, which can be a boon, but in this case a burden. –  mensch Nov 25 '11 at 10:52
mensch, Thanks for your help so far. I've updated my questions to include more information. –  Lawrence Barsanti Nov 25 '11 at 11:55
Thanks! :) Though I'm not sure I'll be able to solve your problem in the end. The SQL for the table structure looks normal and I've just tested a SELECT similar to the one that's causing errors on your part without any problems (SELECT * FROM cake_sessions AS Session WHERE Session.id = 'd1cc24fdacc4f7338fa1f2b4957d22eb'). Could you update your question with the code used to setup the database session? Also, check the Session settings in /app/config/core.php just to be sure. –  mensch Nov 25 '11 at 12:09
add comment


Your Answer



Browse other questions tagged or ask your own question.