0
私はZend Frameworkを初めて使用しています。Zend FrameworkでMySQLデータベースを設定およびアクセスする方法は?
私は、データベースの罰金にアクセスするために、すべてのコントローラで
$db = new Zend_Db_Adapter_Pdo_Mysql(
[
'host' => 'localhost',
'username' => 'user',
'password' => 'pass',
'dbname' => 'database'
]
);
$query = 'SELECT * FROM table_name';
$this->view->rec = $this->db->fetchAll($query);
でMySQLデータベースにアクセスしてみてください。 (私はシングルコンフィグをしたい。)
だから、私はブートストラップ設定、 "テーブル" からデータを取得に、このインスタンスにアクセスする方法
$this->bootstrap('db');
switch (APPLICATION_ENV) {
case 'development' :
// this allows you to profile your queries through the firebug console
$profiler = new Zend_Db_Profiler_Firebug('System Queries');
$profiler->setEnabled(true);
$this->getPluginResource('db')->getDbAdapter()->setProfiler($profiler);
break;
case 'production' :
// if you use meta caching in production, which you should :)
// Zend_Db_Table_Abstract::setDefaultMetadataCache($this->_cache);
break;
}
を経由してみては?
その他の解決策はありますか?
ありがとうございました!