CodeIgniter Forums
Timestamp is always '0000-00-00 00:00:00' in ci_sessions table - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Timestamp is always '0000-00-00 00:00:00' in ci_sessions table (/showthread.php?tid=79595)



Timestamp is always '0000-00-00 00:00:00' in ci_sessions table - louieuow - 07-06-2021

Hi All
I am referring to CI 4.1.3
There is a bug in the system file Session\Handlers\DatabaseHandler.php in the function "public function write($sessionID, $sessionData): bool"
I added this line of code  (below) just above the 2 "return true;"  lines in this function (lines 225 and 251)
$fp = fopen('c:\temp\session.txt', 'a'); fwrite($fp,$this->db->getLastQuery()."\n");fclose($fp);
To write out the queries that are used to update the ci_sessions table when $sessionDriver is set to the DatabaseHandler.
The following is the sample SQL statements for both and INSERT and an UPDATE of ci_sessions generated by this function 
//-------------------------
INSERT INTO `ci_sessions` (`id`, `ip_address`, `timestamp`, `data`) VALUES ('qtigi184f4bh2joblluam9t2a78sioeb', '130.130.211.181', 'now()', '__ci_last_regenerate|i:1625558640;session_id|s:32:\"qtigi184f4bh2joblluam9t2a78sioeb\";_ci_previous_url|s:57:\"http://chios.ad.uow.edu.au/law_lip/public/index.php/login\";')

UPDATE `ci_sessions` SET `timestamp` = 'now()', `data` = '__ci_last_regenerate|i:1625558640;session_id|s:32:\"qtigi184f4bh2joblluam9t2a78sioeb\";_ci_previous_url|s:57:\"http://chios.ad.uow.edu.au/law_lip/public/index.php/login\";status|s:2:\"OK\";user_id|s:2:\"la\";account_type|i:1;user_rec_id|s:1:\"1\";user_rec|s:0:\"\";menus|s:0:\"\";application_id|i:0;'
WHERE `id` = 'qtigi184f4bh2joblluam9t2a78sioeb'

//-----------------------------------
The issue causing  the Timestamp to be stored as '0000-00-00 00:00:00' is that the MySQL function NOW() is in quotes so it is treated as a string and timestamp is not assigned the value of NOW(), but the string 'NOW' (the error is in red font above).
This function will have to be adjusted so that NOW() is not quoted when the SQL is generated
Regard
louieuow


RE: Timestamp is always '0000-00-00 00:00:00' in ci_sessions table - InsiteFX - 07-06-2021

Please create an issue on GitHub.

CodeIgniter 4 Develop Branch

On the top left you will see isssues click on that and fllow the directions.


RE: Timestamp is always '0000-00-00 00:00:00' in ci_sessions table - paulbalandan - 07-06-2021

No need to raise an issue. This has been fixed recently.