CodeIgniter Forums
Session database errors and query builder chaining - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Session database errors and query builder chaining (/showthread.php?tid=61501)



Session database errors and query builder chaining - djroshi - 04-20-2015

I am having an issue on production server after upgrading to CI3. Additional conditions are being added to a session database query by the query builder. The two where clauses in bold are from a simple select query in an normal CI model, and I am not sure why they are being applied to an update query within the CI_Session_database_driver class. My suspicion is that because these session handler functions are registered using PHPs session_set_save_handler that they have access to the CI->db object that is concurrent with other running processes. Any thoughts on resolving this?

A Database Error Occurred
Error Number: 1054
Unknown column 'ur.user_id' in 'where clause'

UPDATE `ci_sessions` SET `timestamp` = 1429568240, `data` = '__ci_last_regenerate|i:1429564536;'
WHERE `ur`.`user_id` = '1'
AND `r`.`active` = 1

AND `id` = 'efe35de70aeeab890cb68562d8058cad6e48d52b'

Filename: libraries/Session/drivers/Session_database_driver.php
Line Number: 243


RE: Session database errors and query builder chaining - mwhitney - 04-21-2015

My suspicion would be that you are using query caching and the session is being updated while the cache is enabled, but there's not much I can do to help without seeing the code for the model.


RE: Session database errors and query builder chaining - djroshi - 04-21-2015

Thanks for your help. Query caching is definitely not enabled anywhere (either in config or manually using the cache_on() function) also, the session database driver would be throwing an error:

PHP Code:
elseif ($this->_db->cache_on)
{
throw new 
Exception('Configured database connection has cache enabled. Aborting.'); 

The model itself is utterly boring, the function in question (which is the only function in the codebase to have these specific where clauses):

PHP Code:
public function get_user_roles($user_id) {
 
       $this->db->select('r.role_id, r.role_name, r.permissions')
 
                ->from('user_role_tbl as ur')
 
                ->join('role_tbl as r''ur.role_id = r.role_id')
 
                ->where('ur.user_id'$user_id)
 
                ->where('r.active'1);

 
       $res $this->db->get();
 
       
        if 
($res->num_rows() == 0) {
 
           return array();
 
       }
 
       
        $data 
= array();
 
       
        foreach
($res->result() as $row) {
 
           ...return the data in array, etc... 

If you can see any issue here please let me know...


RE: Session database errors and query builder chaining - mwhitney - 04-23-2015

Where is the session being used?


RE: Session database errors and query builder chaining - Adrianfan - 04-24-2015

Hi all,

Experiencing the same issue.

Brand new installation of CI 3 from download. Enabled autoload session. Setup database for session. Error as above any thoughts on this would be appreciated.