根据输入的登录字段选择正确的数据库

时间:2014-07-02 10:43:37

标签: codeigniter codeigniter-2

我有3个登录字段(名称,通行证,公司ID)。现在,当用户点击"登录我"按钮CI应根据公司ID选择并使用数据库(并检查此数据库中的用户,当他登录时,在整个会话中使用此数据库/每个公司都有自己的数据库/)。

我该怎么做?

我找到了 this ,但看起来它不是正确的解决方案。

非常感谢

1 个答案:

答案 0 :(得分:0)

<强> CodeIgniter: Connection to your Database

也许上面的链接会帮助你。 您必须为特定公司设置新的数据库连接。在CodeIgniter中,它非常简单。

将其与 THIS PROBLEM 结合使用,即可访问database-config中设置的数据库设置。

示例:

<?php
$config = array();
$config['hostname'] = $this->db->hostname;
$config['username'] = $this->db->username;
$config['password'] = $this->db->password;
$config['database'] = 'companydb';
$config['dbdriver'] = $this->db->dbdriver;

$companydb = $this->load->database($config);
$companydb->query('SELECT ... FROM ... WHERE ...');
?>