Welcome Guest, Not a member yet? Register   Sign In
Error when session table is updated


I get the following error message when I try to load a page:
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 '`< 1340198948`' at line 2

DELETE FROM `jaz_sessions` WHERE `last_activity` `< 1340198948`

Filename: D:\xampp\htdocs\journaldujazz\system\database\DB_driver.php

Line Number: 330

When I refresh the page the message is gone. I autoload the session class btw.
It's my first project using CI 2.1.1 (I did the upgrade from 2.1 to 2.1.1,
overwriting system folder and index.php on root)

Does anyone know what may cause that error message?

recreate your session table with the latest table schem from
section : Saving Session Data to a Database

I don't think it's the table. It looks like CI is getting the "protect identifiers" wrong in that query. Notice the tickmarks: '`< 1340198948`'

I'd file a bug report on that one. Strange that no one else has seen this?

I did a table export to compare with the Userguide table template:

CREATE TABLE `jaz_sessions` (
  `session_id` varchar(40) COLLATE utf8_bin NOT NULL DEFAULT '0',
  `ip_address` varchar(45) COLLATE utf8_bin NOT NULL DEFAULT '0',
  `user_agent` varchar(150) COLLATE utf8_bin NOT NULL,
  `last_activity` int(10) unsigned NOT NULL DEFAULT '0',
  `user_data` text COLLATE utf8_bin NOT NULL,
  PRIMARY KEY (`session_id`)

I don't know what happend to me - I could swear I defined
utf8_unicode while I have utf8_bin as COLLATE.. never happend
to me before. I guess that was the problem?

Sorry I didn't checkthat before - I guess I did the mistake when
setting up the database COLLATE because I allways take session tables
from older projects (export/import) having COLLATE set to utf8_unicode.
But when setting the DB itself to utf8_bin I guess the tabel COLLAT is
overwritten ..

I will re-setup the DB and table - in case I get the same error I'll post
that here.

Thanks for you help anyway!

LuckyFella73, that is the wrong table here is the correct one
-- ------------------------------------------------------------------------

-- Table structure for CodeIgniter `ci_sessions`.
DROP TABLE IF EXISTS `ci_sessions`;

  `session_id`    varchar(40)           DEFAULT '0' NOT NULL,
  `ip_address`    varchar(45)           DEFAULT '0' NOT NULL,
  `user_agent`    varchar(120)                      NOT NULL,
  `last_activity` int(10)      unsigned DEFAULT 0   NOT NULL,
  `user_data`     text,
  PRIMARY KEY (`session_id`),
  KEY `last_activity_idx` (`last_activity`)

-- ------------------------------------------------------------------------
--  `user_data` text,       COMMENT - maximum length of 65535 characters.
--  `user_data` mediumtext, COMMENT - maximum length of 16777215 characters.
--  `user_data` longtext,   COMMENT - maximum length of 4294967295 characters.
-- ------------------------------------------------------------------------

Not sure how a table will affect a query that is written wrong. The protect identifiers is generating the wrong sql. There are tickmarks around `< 1340198948` which is breaking the query. This was a problem with the initial release of 2.1.1, which they claim they fixed and rereleased (haven't tested it). Are you sure all of your code is up to date with the most current version of CI, downloaded since they rereleased it?

He's missing the last_activity_idx KEY according to his table which would throw the error,
But not sure, I am using the newest CI.

Well, that needs to be fixed as well, but the specific error has to do with this wrongly generated internal CI query, which would never work no matter what table it was tried on due to the tickmarks around the "less than timestamp", which isn't a field:
DELETE FROM `jaz_sessions` WHERE `last_activity` `< 1340198948`

True, I belive thay have fixed it with the newest CI ver on GitHub.

@ Cronix

Quote:Are you sure all of your code is up to date with the most current version of CI, downloaded since they rereleased it?

I'm quite sure I downloaded the initial version - didn't know that it was
rereleased! I will update my table again, download the corrected version 2.1.1
and replace my system folder again.

@ InsideFX
Thank you for giving me the table sql. I'm still confused because the upgrade
instructions from 2.1.0 to 2.1.1 state:
Quote:ALTER TABLE ci_sessions CHANGE ip_address ip_address varchar(45) default '0' NOT NULL

So I guess I have to take your table sql and just replace the "16" for the
column ip_address with "45".

Thanks again for all the input!

Theme © iAndrew 2016 - Forum software by © MyBB