本文介紹了Cakephp 無法即時更改數(shù)據(jù)庫的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我試圖從循環(huán)中連接多個數(shù)據(jù)庫,但看到 CakePHP 無法更改 database
,只能更改其他信息(如用戶/密碼/主機(jī)).
app/Config/database.php
app/Controller/CronController.php
$companys = $this->Company->find('all');foreach($companys as $company) {$設(shè)置=數(shù)組('數(shù)據(jù)源' =>'數(shù)據(jù)庫/Mysql','主機(jī)' =>$company['Company']['host'],'登錄' =>$company['公司']['用戶名'],'密碼' =>$company['公司']['密碼'],'數(shù)據(jù)庫' =>$company['Company']['database'],);ConnectionManager::drop('client');$db = ConnectionManager::create('client', $settings);嘗試 {調(diào)試($this->MyModel->find('first'));} 捕獲(異常 $e){echo '';echo "異常: ", $e->getMessage(), "
";/*調(diào)試($this->MyModel->getDataSource());輸出:[...][配置] =>大批([持久] =>[主持人] =>0.0.0.0//正確的主機(jī)[登錄] =>root//正確登錄[密碼] =>pass//正確的密碼[數(shù)據(jù)庫] =>數(shù)據(jù)庫1[端口] =>3306[數(shù)據(jù)源] =>數(shù)據(jù)庫/Mysql[前綴] =>[編碼] =>utf8)[...]*
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!