CodeIgniter4
CodeIgniter4 copied to clipboard
[SQLSRV] Session DatabaseHandler
PHP Version
7.4
CodeIgniter4 Version
4.1.8
CodeIgniter4 Installation Method
Manual (zip or tar.gz)
Which operating systems have you tested for this bug?
Windows
Which server did you use?
cgi-fcgi
Database
SQLSRV 11.0.5058
What happened?
Exception 'now' is not a recognized built-in function name [SQLSRV].
I'm running Codeigniter in the configuration parameters mentioned above and when I set the application settings to store the sessions in the database (public $sessionDriver = 'CodeIgniter\Session\Handlers\DatabaseHandler';) and I created the table "ci_sessions" in the SQL Server database but when I refresh any page I come across with one exception: Informing that the now() function does not exist.
Steps to Reproduce
Just put it in the App.php settings to store the sessions in the SQL Server database, create the session storage table in the database and that's it.
Expected Output
Shouldn't give this exception, I believe this now() function should be replaced by getdate() if $this->platform is "sqlsrv"
Anything else?
Searching a little more for this problem in the file SYSTEMPATH/Session/Handlers/DatabaseHandler.php I verified that within the methods of the database queries there are database queries like this (line 177):
...
if (! $this->db->table($this->table)->set('timestamp', 'now()', false)->insert($insertData)) {
return $this->fail();
}
...
inside the set() method, the now() function does not work in the case of SQL Server, when I changed this code snippet to:
...
if (! $this->db->table($this->table)->set('timestamp', 'getdate()', false)->insert($insertData)) {
return $this->fail();
}
...
completely resolved the errors and the code works fine. I believe that to solve this bug, I can insert a code snippet where I can identify through the variable $this->platform which type of database is and separate which method is proper for each corresponding platform.
Sorry, this is not a bug. We don't support SQLSRV as a session database now.
Only MySQL and PostgreSQL databases are officially supported, due to lack of advisory locking mechanisms on other platforms. https://codeigniter4.github.io/CodeIgniter4/libraries/sessions.html#databasehandler-driver
Sorry, this is not a bug. We don't support SQLSRV as a session database now.
Maybe then throw an exception that the DBMS is not supported?
It seems SQL Server has advisory locking mechanisms. https://dba.stackexchange.com/questions/176424/does-microsoft-sql-server-offer-an-advisory-locks-feature-like-postgres
If someone implements DatabaseHandler...