Php 无法在Zend中连接到MySQL

Php 无法在Zend中连接到MySQL,php,mysql,zend-framework,Php,Mysql,Zend Framework,我正在尝试使用连接zend应用程序中的mysql表(身份验证)。但无法获取DbTable的实例。我只是更改了我申请表中的密码 我有映射器类似这样的东西: class Model_Authentication_Mapper { protected $_dbTable; public function setDbTable( $dbTable ) { if (is_string( $dbTable ) ) { $dbTable = new

我正在尝试使用连接zend应用程序中的mysql表(身份验证)。但无法获取DbTable的实例。我只是更改了我申请表中的密码

我有映射器类似这样的东西:

class Model_Authentication_Mapper {

    protected $_dbTable;

    public function setDbTable( $dbTable ) {

        if (is_string( $dbTable ) ) {
            $dbTable = new $dbTable();
        }
        if ( !$dbTable instanceof Zend_Db_Table_Abstract ) {
            throw new Exception( 'Invalid table data gateway provided' );
        }
        $this->_dbTable = $dbTable;
        return $this;
    }

    public function getDbTable() {

        if (null === $this->_dbTable) {
            $this->setDbTable( 'Model_Authentication_DbTable' );
        }
        return $this->_dbTable;
    }

    public function getRecordById( $id ) {
     $table = $this->getDbTable();
     // Other code here
    }

}
class Model_Authentication_DbTable extends Zend_Db_Table_Abstract {
    protected $_name    = 'Authentication';
}
DbTable如下所示:

class Model_Authentication_Mapper {

    protected $_dbTable;

    public function setDbTable( $dbTable ) {

        if (is_string( $dbTable ) ) {
            $dbTable = new $dbTable();
        }
        if ( !$dbTable instanceof Zend_Db_Table_Abstract ) {
            throw new Exception( 'Invalid table data gateway provided' );
        }
        $this->_dbTable = $dbTable;
        return $this;
    }

    public function getDbTable() {

        if (null === $this->_dbTable) {
            $this->setDbTable( 'Model_Authentication_DbTable' );
        }
        return $this->_dbTable;
    }

    public function getRecordById( $id ) {
     $table = $this->getDbTable();
     // Other code here
    }

}
class Model_Authentication_DbTable extends Zend_Db_Table_Abstract {
    protected $_name    = 'Authentication';
}
当它执行
$table=$this->getDbTable()时在Mapper中,firebug控制台中出现以下错误:

An error occurred
Application error
Message: No adapter found for Model_Authentication_DbTable
如何为此数据库表设置适配器

有人知道这件事吗


谢谢找到解决方案。我只是注释掉application.ini中的一些行,一切正常:

[production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.params.displayExceptions = 1

;[staging : production]

;[testing : production]
;phpSettings.display_startup_errors = 1
;phpSettings.display_errors = 1

;[development : production]
;phpSettings.display_startup_errors = 1
;phpSettings.display_errors = 1
;resources.frontController.params.displayExceptions = 1

resources.db.adapter = "pdo_mysql"
resources.db.params.host = "localhost"
resources.db.params.username = "root"
resources.db.params.password = ""
resources.db.params.dbname = "bbname"
resources.db.isDefaultTableAdapter = true

您是否尝试过使用zf工具?以下命令应帮助您在MySQL数据库的生产部分中创建db适配器:

zf.sh configure db-adapter "adapter=PDO_MYSQL&host=localhost&dbname=test&username=testuser&password=testpasswort&charset=utf8" production

只需确保您的机器上安装了MySQL的PDO驱动程序。

您无需对这些行进行注释。只需将db信息移动到[production]部分的末尾。以下部分将继承前面部分的配置。还要注意的是,在开发过程中,您需要添加到服务器配置中:SetEnv APPLICATION_ENV development,这样您就可以看到错误(这就是开发部分中的phpSettings.display_startup_errors等的原因)。@user570783:您说得对。感谢您对这篇文章的兴趣。