hengsopheak hengsopheak -4 years ago 121
PHP Question

why I always got duplicated value of table session in Codeigniter.2.1.2?

Session in Codeigniter will automatic generated but why I always duplicated value like this. I don't understand how to find those problem

A Database Error Occurred

Error Number: 1062

Duplicate entry '2147483647' for key 'PRIMARY'

INSERT INTO `tb_session` (`session_id`, `ip_address`, `user_agent`, `last_activity`, `user_data`) VALUES ('b74806cb089d1c9b090dd1455d320e42', '::1', 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36', 1427507006, '')

Filename: D:\My data\project\wamp\www\Ecom\system\database\DB_driver.php

Line Number: 331


And I got other

A Database Error Occurred

Error Number: 1062

Duplicate entry '0' for key 'PRIMARY'

UPDATE `tb_session` SET `last_activity` = 1427511803, `session_id` = 'dde3dc48ecee1cd6650b2025ed819573' WHERE session_id = '33191cc74ea4a2dde501c770b0292f7c'

Filename: D:\My data\project\wamp\www\Ecom\system\database\DB_driver.php

Line Number: 331

Answer Source

It seems you have modified your sessions table to have the primary key as an int(11). The original CodeIgniter table has the session_id as a varchar primary key.

See that the query tries to insert 'b74806cb089d1c9b090dd1455d320e42' as the session_id? That should be the primary key's value, but your error is saying that you tried to insert the '2147483647' value, which isn't even on the query.

This leads me to believe that you somehow have another field which is an integer as the primary key, and now it has reached the int(11) maximum value of 2147483647 so it's throwing that error.

Solution: just remove the new primary key, restore the table to the original structure, and the problem should go away. You don't even need to truncate the table.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download