1

My configuration on CI is pretty standard.

$config['sess_cookie_name']     = 'ci_session';
$config['sess_expiration']      = 0;
$config['sess_expire_on_close'] = TRUE;
$config['sess_encrypt_cookie']  = TRUE;
$config['sess_use_database']    = TRUE;
$config['sess_table_name']      = 'ci_sessions';
$config['sess_match_ip']        = TRUE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update']  = 2000;

I don't use expire because I am testing the system, I know it's not good practice. I use a high sess_time_to_update because of AJAX requests destroying the session (a CI bug).

I now have a new bug which I believe has to do with my code but I'm not sure how to fix it.

I've been storing my sessions in a database using one database connection. The flashdata to display error messages has been working perfectly.. until recently. Now the flashdata wont set when I introduced a second database connection.

$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'emp';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = FALSE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

$db['dil']['hostname'] = 'localhost';
$db['dil']['username'] = 'root';
$db['dil']['password'] = '';
$db['dil']['database'] = 'dil';
$db['dil']['dbdriver'] = 'mysql';
$db['dil']['dbprefix'] = '';
$db['dil']['pconnect'] = TRUE;
$db['dil']['db_debug'] = TRUE;
$db['dil']['cache_on'] = FALSE;
$db['dil']['cachedir'] = '';
$db['dil']['char_set'] = 'utf8';
$db['dil']['dbcollat'] = 'utf8_general_ci';
$db['dil']['swap_pre'] = '';
$db['dil']['autoinit'] = TRUE;
$db['dil']['stricton'] = FALSE;

After I set my flash data I display it with var_dump and print_r and it prints a boolean: false. When I don't use a second connection it works fine. Any ideas? Some people say to not store sessions in DB but I need to for security.

Update: I that assumed the set_flashdata didnt insert it into the database so I checked to be sure and that is the problem. set_flashdata is not inserting the flash data. Other pages with two connections works fine (the notifications) just this page isnt.

Update 2: When I set the flashdata and exit; right after i look in the database and there is a message: "You need to login to see this page". This is set when someone isnt logged in. Hm.. definitely something weird going on...

Update 3: after using the log_message( in the SESS_WRITE( function in the Core/libraries/session file I see that it sets the message correctly but then there is an extra refresh some how...

ERROR - 2012-11-23 15:38:39 --> "logged_in";b:1;}
ERROR - 2012-11-23 15:38:39 -->"logged_in";b:1;s:22:"flash:new:notification";a:2:{s:4:"type";s:7:"success";s:7:"message";s:31:"Image was updated successfully.";}}

SOLVED Thanks to mohan.gade I've found a solution.

When working with multiple databases with the way I set mine up (default, db1, db2 etc..) when you load a new database into a variable when you autoload the default database it resets the $this->db.

$this->db1 = $this->load->database('db1', TRUE);

So the fix...although not fun...is to load all databases manually when working with multiple connections.

$this->db = $this->load->database('default', TRUE);
$this->db1 = $this->load->database('db1', TRUE);

Thanks!

1 Answer 1

1

How doyou make database connection ? Is config/autoload library contains 'database' ? then remove it . do the database conncetion manually. If you need to connect to more than one database simultaneously you can do so as follows: $emp = $this->load->database('emp', TRUE); $dil = $this->load->database('dil', TRUE); And access the database functions following way $emp->query(); insted of regular method $this->db->query() for more details go to the http://codeigniter.com/user_guide/database/connecting.html

Sign up to request clarification or add additional context in comments.

1 Comment

After days of debugging this seems to be the issue. I will mark this as answered and give a brief solution in my question at the bottom. Thank you so much.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.