2015-07-20 39 views
0

我想從數據庫表中檢索數據到cakephp shell腳本中。在Cakephp Shell中獲取數據庫表數據

我試着用下面的代碼,但它不工作。

代碼:

App::import('Model', 'ModelName'); 
$this->ModelName = ClassRegistry::init('ModelName'); 
$result = $this->ModelName->find('all'); 

錯誤:

Database connection "Mysql" is missing, or could not be created. 

我已經搜索了很多在谷歌,但我不能找到任何合適的回答吧。

請幫助我解決這個問題。

+0

可能重複[如何從Cake Shell讀取數據庫配置設置?](http://stackoverflow.com/questions/3895660/how-can-i-read-the-db-configuration-settings-從一個蛋糕殼) – RiggsFolly

+0

我已經試過這個,但它不工作。它發生錯誤這個錯誤:「Class'ConnectionManager'not found」 –

+0

我已經解決了「ConnectionManager找不到」的錯誤,但是發生了同樣的錯誤,在我的問題中提到 –

回答

1

Yehhh ...我發現它...

萬一別人面對這一點,它不是有訪問MySQL一個PHP的情況下,客戶端庫。在系統上安裝MySQL服務器不是正確的修復方法。修復ubuntu(和PHP 5):

sudo apt-get install php5-mysql 
0

對於CakePHP的2.x的嘗試:

$this->ModelName = ClassRegistry::getObject('ModelName'); 

if (!obj) { 
    App::import('Model', 'ModelName'); 
    $this->ModelName = new ModelName(); 
} 
0

它也可能是配置問題,請確保您的應用程序/ Config/database.php包含正確的憑據。 可能會改變

127.0.0.1

本地主機

和嘗試。