Skip to content

[SQLSRV] Session DatabaseHandler #5693

@websignsistemas

Description

@websignsistemas

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    databaseIssues or pull requests that affect the database layerenhancementPRs that improve existing functionalities

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions