Welcome Guest, Not a member yet? Register   Sign In
[Solved] duplicate database entry with database session driver
#1

(This post was last modified: 02-11-2015, 05:02 AM by betz0r.)

Hello,

i am experiencing some troubles with the database session driver:

Code:
Error Number: 1062

Duplicate entry 'SESSIONIDKEYREMOVED' for key 'PRIMARY'

INSERT INTO `ci_sessions` (`id`, `ip_address`, `timestamp`, `data`) VALUES ('SESSIONIDKEYREMOVED', 'IPADDRESSREMOVED', 1423636803, '')

Filename: libraries/Session/drivers/Session_database_driver.php

Line Number: 216

How can i "catch" this error without modifing the core/session package but in the application code? I don't know where this duplicate entry is coming from and why it's happening, but it brakes the whole website...
Reply
#2

You've got sess_match_ip turned on, but you've kept only the 'session_id' field as primary key and you're visiting the site from another IP address ...
Reply
#3

Thanks a lot, i read about the primary key earlier but forgot indeed to change it in my database.
This is solved then!

Keep on the good work ;-)
Reply
#4

I"m running into this error a lot and I think it's setup right.

Query:

   
Code:
DROP TABLE `ci_sessions`;
   CREATE TABLE IF NOT EXISTS `ci_sessions` (
       `id` varchar(40) NOT NULL,
       `ip_address` varchar(45) NOT NULL,
       `timestamp` int(10) unsigned DEFAULT 0 NOT NULL,
       `data` blob NOT NULL,
       PRIMARY KEY (id),
       KEY `ci_sessions_timestamp` (`timestamp`)
   );
   ALTER TABLE ci_sessions ADD CONSTRAINT ci_sessions_id_ip UNIQUE (id, ip_address);

My session config (I needed a clause for when running tests):


Code:
   $config['sess_driver'] = (defined('CODECEPTION_TEST') ? 'files' : 'database');
   $config['sess_cookie_name'] = 'cisession';
   $config['sess_expiration'] = 7200;
   $config['sess_save_path'] = ($config['sess_driver'] === 'files' ? dirname(APPPATH) . '/sessions/' : 'ci_sessions');
   $config['sess_match_ip'] = true;
   $config['sess_time_to_update'] = $config['sess_expiration'];


The error I get:


Code:
   error - 2015-06-17 21:48:46 --> Query error: Duplicate entry 'fa431390cb8caae340986a0dbc751e2890890788' for key 'PRIMARY' - Invalid query: INSERT INTO `ci_sessions` (`id`, `ip_address`, `timestamp`, `data`) VALUES ('fa431390cb8caae340986a0dbc751e2890890788', '68.235.73.5', 1434595726, '')
Reply




Theme © iAndrew 2016 - Forum software by © MyBB