CodeIgniter
CodeIgniter copied to clipboard
Error with database sessions in remote database - Undefined property: stdClass::$ci_session_lock.
Sessions fail with the remote database only
I configured the session options in application/config.php
like so:
$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
$config['cookie_secure'] = TRUE;
$config['cookie_httponly'] = TRUE;
The Issue
This error occurs with the remote database but does not occur with the local database.
Severity: Warning --> Undefined property: stdClass::$ci_session_lock system/libraries/Session/drivers/Session_database_driver.php 409
Severity: Warning --> session_start(): Failed to read session data: user (path: ****) system/libraries/Session/Session.php 137
The Environment
- Codeigniter 3.1.13
- PHP 8.0-8.2.6
- Remote database: Planetscale
- Local databse: MariaDB 10.4.20
@drkNsubuga it's not an error, but warning
https://github.com/bcit-ci/CodeIgniter/blob/develop/system/libraries/Session/drivers/Session_database_driver.php#L409 according to the message, sql query does not return expected result (null):
GET_LOCK(str,timeout)
Returns 1 if the lock was obtained successfully, 0 if the attempt timed out (for example, because another client has previously locked the name), or NULL if an error occurred (such as running out of memory or the thread was killed with mysqladmin kill).
also, check your db config: https://codeigniter.com/userguide3/libraries/sessions.html#database-driver
You must have the Query Builder enabled. You can NOT use a persistent connection. You can NOT use a connection with the cache_on setting enabled.