2014-02-18 29 views
1

是否可以使用不同的數據庫通過Ion Auth認證用戶? 我想創建一個專用於用戶身份驗證的數據庫。所以,它應該與事務數據庫分開。 如何做到這一點?Ion Auth(Codeigniter) - 如何使用不同的數據庫

謝謝。

+0

你在使用什麼數據庫? – arty

+0

[Codeigniter - 多個數據庫連接]的可能重複(http://stackoverflow.com/questions/8268853/codeigniter-multiple-database-connections) – arty

回答

2

總之...是的,您可以使用不同的數據庫進行身份驗證。除了默認配置之外,您還需要在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模型使用第二個DB配置,你會裝載數據庫時進行設置。

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

然後更改所有的數據庫查詢模型與$auth_db更換$this->db。因此,$this->db->select('password, salt')將變成$auth_db->select('password, salt')

更多參考看看 - http://ellislab.com/codeigniter/user-guide/database/connecting.html

希望幫助!

2

最簡單的方法是擴展MY_Mark的說法。

在ion_auth_model.php的構造函數創建新的數據庫配置

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

那麼做到這一點:

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

它應該後只是工作。

相關問題