在 Zend 當中,除了可以使用 Zend_Db::factory 建立 DB Adapter 之外,也可以直接將設定檔寫在 application.ini 中直接使用

application.ini

resources.db.adapter = "PDO_MYSQL"
resources.db.params.dbname = ""
resources.db.params.host = "localhost"
resources.db.params.username = ""
resources.db.params.password = ""
resources.db.params.driver_options.1002 = "SET NAMES utf8"
resources.db.isDefaultTableAdapter = true

controller

$dbAdapter = Zend_Db_Table::getDefaultAdapter();
$sth = $dbAdapter->query("SELECT * FROM `member`");
print_r($sth->fetch());
Categories: ZendFramework