我是 Zend 框架的新手。我正在尝试使用 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
谁能指出我正确的方向?