我是新來的Zend框架。我試圖使用Zend Registry連接數據庫,但我無法做到。使用Zend Registry連接到數據庫
這是我的引導類。
<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
public function _initDb(){
$db = new Zend_Db_Adapter_Pdo_Mysql(
array(
'host' => 'localhost',
'username' => 'ragn',
'password' => 'app',
'dbname' => 'apple'
)
);
Zend_Db_Table_Abstract::setDefaultAdapter($db);
Zend_Registry::set('db', $db);
}
}
?>
這裏是我的IndexController
類。
class IndexController extends Zend_Controller_Action {
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
$db = Zend_Registry::get('dbadapter');
$select = new Zend_Db_Select($db);
$select = $db->select();
$select = $db->select() -> from(
array('client' => 'client'),
array ('idclient')) -> join(array('apartmentclient' => 'apartmentclient'),
'client.idclient = apartmentclient.idclient',
array ('idapartment')) -> join(array('description' => 'description'),
'apartmentclient.idapartment = description.idapartment',array ('title'));
$stmt = $select->query();
$result = $stmt->fetchAll();
$Settext = array();
$SetName = array();
$SetName = "$result[2]";
$Settext = "Hi!Can you please provide feedback for the apartment";
$this->view->Settext = $Settext." ".$SetName;
}
}
我還有詳細的application.ini文件。
resources.db.adapter = PDO_MYSQL
resources.db.isDefaultAdapter = true
resources.db.params.host = localhost
resources.db.params.username = ragn
resources.db.params.password = app
resources.db.params.dbname = apple
任何人都可以指向正確的方向嗎?
你是什麼意思「無法」?數據庫是否限制訪問?你有適當的權限連接到數據庫?該數據庫是否與* exact *用戶和登錄憑據一起存在?你能在這裏填空嗎? – Makoto 2012-07-15 23:34:05
Hi.Thanks的答覆。我只是試圖查詢它。它說最大執行時間30秒超過。是正在嘗試使用正確的登錄憑據。我不知道我需要在其他文件中的條目像.htaccess?..... – user1230541 2012-07-15 23:40:15
你真的只需要在application.ini或bootstrap.php中設置你的數據庫適配器。您正在設置相同的適配器兩次。'$ db = new Zend_Config($ this-> getOption('db');'在你的引導程序中將從application.ini獲得適配器 – RockyFord 2012-07-16 04:27:10