开发者

Unable to connect to MySQL in Zend

开发者 https://www.devze.com 2023-02-04 03:33 出处:网络
I am trying to connect mysql table(Authentication) in zend application using this tutorial. But unable to get instance of DbTable. I only changed the directory structure in my application.

I am trying to connect mysql table(Authentication) in zend application using this tutorial. But unable to get instance of DbTable. I only changed the directory structure in my application.

I have Mapper something like this:

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
    }

}

And DbTable like this:

class Model_Authentication_DbTable extends Zend_Db_Table_Abstract {
    protected $_name    = 'Authentication';
}

When It execute $table = $this->getDbTable(); in Mapper it gives me following error in firebug console:

An error occurred
Application error
Message: No adapter found for Model_Authentication_DbTable

How to set adapter for this DbTable ?

Anyone know about this ??

Thanks


Have you tried to use the zf tools? The following command should help you to create a db adapter in your production section for the MySQL database:

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

Just be sure you have the PDO driver for MySQL installed on your machine.


Find the solution. I just comment out some lines in application.ini and everything is working:

[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
0

精彩评论

暂无评论...
验证码 换一张
取 消