我的application.in I文件中有以下内容
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文件中使用以下命令也很容易
`受保护的函数_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未定义。
问题是我怎么才能拿到$db?
我试过以下方法:
$db=Zend_db_Table::getDefaultAdapter();
$db=$this->getPluginResource('db');
我假设它不工作,因为它连接到数据库后,做了所有的事情在我的引导。我该怎么解决?

最佳答案

这应该会有帮助,创建一个$db变量,如下所示:

$this->bootstrap('db');
$db = $this->getPluginResource('db')->getDbAdapter();

关于php - 使用ZFDebug的Zend Framework,如何获取数据库适配器,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7046020/

10-16 15:48