我的 application.ini 文件中有以下内容
resources.db.adapter = "PDO_MYSQL"
resources.db.params.host = "localhost"
resources.db.params.username = ".."
resources.db.params.password = ".."
resources.db.params.dbname = "lsc3_base"
resources.db.isDefaultTableAdapter = true
现在一切正常,我可以毫无问题地查询数据库。
我正在尝试安装 ZFDebug,在我的主 bootstrap.php 文件中使用以下内容也很容易
` protected 函数 _initZFDebug() { $autoloader = Zend_Loader_Autoloader::getInstance(); $autoloader->registerNamespace('ZFDebug');
$options = array(
'plugins' => array('Variables',
'Time',
#'Auth',
'Memory',
'Registry',
'Database' => array('adapter' => $db),
'File' => array('basePath' => '/path/to/project'),
#'Cache' => array('backend' => $cache->getBackend()),
'Exception')
);
$debug = new ZFDebug_Controller_Plugin_Debug($options);
$this->bootstrap('frontController');
$frontController = $this->getResource('frontController');
$frontController->registerPlugin($debug);
}
` 现在这显然给了我一条通知,说 $db undefined。
问题是如何获得 $db?
我试过以下方法: $db = Zend_Db_Table::getDefaultAdapter(); $db = $this->getPluginResource('db');
我假设它不起作用,因为它在我的 Bootstrap 中完成所有操作后连接到数据库。我该如何解决这个问题?
最佳答案
这应该有帮助,像这样制作一个 $db 变量:
$this->bootstrap('db');
$db = $this->getPluginResource('db')->getDbAdapter();
关于php - Zend Framework with ZFDebug,如何获取数据库适配器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7046020/