如何在具有多个数据库的CodeIgniter中存储数据库会话? [英] How do I store database sessions in CodeIgniter with multiple databases?

查看:72
本文介绍了如何在具有多个数据库的CodeIgniter中存储数据库会话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用codeigniter,直到日期我使用基于cookie的会话..但现在会话的大小增加,所以我需要将其存储在数据库中。



我有多个数据库(超过3)连接到我的应用程序。我怎么可以具体使用ci_sessions表来存储会话?



当我说$ config ['sess_use_database' ] = TRUE;我的应用程序空白。显示一个平面白页。



这是因为从多个数据库连接,codeigniter没有找到确切的数据库来存储会话。



我如何实现相同?
感谢

解决方案

这个问题已经有一段时间了,但我觉得结论性的答案



system / libraries /



所使用的默认代码是(Line 85)。如果指定了Session.php ):



  //我们使用数据库吗?如果是,加载它
if($ this-> sess_use_database === TRUE AND $ this-> sess_table_name!='')
{
$ this-> CI-> ; load-> database();
}

这理论上应该加载默认数据库。由于某些原因,这对我没有工作。我必须修改代码以专门调用默认数据库。



您应该使用的代码从默认 database:



  //我们使用数据库吗?如果是,加载它
if($ this-> sess_use_database === TRUE AND $ this-> sess_table_name!='')
{
$ this-> CI-> ; load-> database('default',TRUE);
}

如果您要使用不同的数据库,只需更改<$ c $

如果在调用会话数据之前加载另一个数据库,则需要再次指定会话数据。会话将继续尝试从当前活动的数据库中提取。


I am using codeigniter and till date I was using cookie based sessions.. but now size of sessions is increased so i need to store them in database..

I have multiple database(more than 3) connected to my application..How can i specifically use ci_sessions table to store sessions?

when i say $config['sess_use_database'] = TRUE; my app goes blank. a plane white page is shown.

That is because From multiple database connections codeigniter is not finding exact database to store sessions..

How can i achieve the same? Thanks

解决方案

It has been a while since this question has been asked, but I feel like a conclusive answer is needed.

As of CodeIgniter 2.1.2

When the system/libraries/Session.php is loaded, it also loads a database to use with the sessions, if specified.

The default code used is (Line 85):

// Are we using a database?  If so, load it
if ($this->sess_use_database === TRUE AND $this->sess_table_name != '')
{
    $this->CI->load->database();
}

This should, in theory load the default database. For some reason, this did not work for me. I had to modify the code to specifically call the default database.

The code you should use to pull from the default database:

// Are we using a database?  If so, load it
if ($this->sess_use_database === TRUE AND $this->sess_table_name != '')
{
    $this->CI->load->database('default', TRUE);
}

If you would like to use a different database, just change default to the name of the database which you would like to use.

Note: If you load another database before you call session data, you will need to specify your session data again. The session will continue to try and pull from the currently active database.

这篇关于如何在具有多个数据库的CodeIgniter中存储数据库会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆