Question

I'm using application.ini to bootstrap DB settings and adapter in Zend 1.12

resources.db.adapter = "PDO_MYSQL"
resources.db.params.host = "server"
resources.db.params.port = "3310"
resources.db.params.username = "user"
resources.db.params.password = "pass"
resources.db.params.dbname = "dbname"
resources.db.params.charset = "utf8"
resources.db.isDefaultTableAdapter = true

However, I can't find default adapter in my scripts:

$db = Zend_Db_Table::getDefaultAdapter();

This is giving empty result.

I must use init mentod in Bootstrap to get it working:

protected function _initDbTable() {

        $resource = $this->getPluginResource('db');
        $adapter = $resource->getDbAdapter();
        Zend_Db_Table::setDefaultAdapter($adapter);
    }

Is there any way to setup all just in application.ini ?

Was it helpful?

Solution

You're doing it right. Resources in config need to be bootstrapped just like how you do it. "Zend_Db_Table::setDefaultAdapter($adapter);" because that's what "resources.db.isDefaultTableAdapter = true" for.

See also What is the "right" Way to Provide a Zend Application With a Database Handler

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top