【问题标题】:Ion Auth (Codeigniter) - How to use different databaseIon Auth (Codeigniter) - 如何使用不同的数据库
【发布时间】:2014-03-17 20:44:51
【问题描述】:

是否可以通过 Ion Auth 使用不同的数据库对用户进行身份验证? 我想创建一个仅用于用户身份验证的数据库。因此,它应该与事务数据库分开。 该怎么做?

谢谢。

【问题讨论】:

标签: codeigniter ion-auth


【解决方案1】:

简而言之...是的,您可以使用不同的数据库进行身份验证。除了默认配置之外,您还需要在 application/config/database.php 文件中创建第二个数据库配置(类似于下面)。

$db['default']['hostname'] = "localhost";
$db['default']['username'] = "root";
$db['default']['password'] = "";
$db['default']['database'] = "db_name";
$db['default']['dbdriver'] = "mysql";

$db['authentication']['hostname'] = "localhost";
$db['authentication']['username'] = "root";
$db['authentication']['password'] = "";
$db['authentication']['database'] = "auth_db_name";
$db['authentication']['dbdriver'] = "mysql";

如需进一步参考,请参阅 - http://ellislab.com/codeigniter/user-guide/database/configuration.html

然后您必须修改您的 ion_auth 模型以使用您在加载数据库时设置的第二个数据库配置。

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

然后更改模型中的所有数据库查询,将$this->db 替换为$auth_db

所以,$this->db->select('password, salt') 将变为 $auth_db->select('password, salt')

更多参考请参阅 - http://ellislab.com/codeigniter/user-guide/database/connecting.html

希望有帮助!

【讨论】:

    【解决方案2】:

    最简单的方法是扩展 MY_Mark 所说的内容。

    创建新的数据库配置

    $db['authentication']['hostname'] = "localhost";
    $db['authentication']['username'] = "root";
    $db['authentication']['password'] = "";
    $db['authentication']['database'] = "auth_db_name";
    $db['authentication']['dbdriver'] = "mysql";
    

    然后在 ion_auth_model.php 的构造函数中这样做:

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

    然后它应该就可以工作了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-02-11
      • 1970-01-01
      • 2013-01-14
      • 2011-10-12
      • 1970-01-01
      • 2016-01-23
      • 1970-01-01
      相关资源
      最近更新 更多