Can I install a database adapter for permanent use from the Zend_Db_Table_Abstract class?

I have 2 databases that my site uses, including a central user database, which refers to other databases related to specific sites.

Sometimes it’s enough to call new User(array('db'=>'adapter1'));(but never conveniently); in other cases, for example, when declaring relationships between tables in different databases, there is no way to do this.

Does anyone know a way to specify which database adapter to use from the Zend_Db_Table_Abstract class?

Thanks!

+3
source share
4 answers

, . "tdb", :

protected function _setupDatabaseAdapter()
{
    $this->_db = Zend_Registry::get('tdb');
    parent::_setupDatabaseAdapter();
}

!

+4

Zend_Db_Table_Abstract . :

Zend_Db_Table_Abstract::setDefaultAdapter($adapter);

.

: - , API : http://framework.zend.com/apidoc/core/

+3

$_db .

global $adapter1; //There are better ways than using a global variable

$this->_db = $adapter1;

, - . , , .

+1
source

The init function can be used, it is not used in Zend_Db_Adapter_Abstract,, which can be used in your class to configure all the necessary actions. _setAdaptertakes a string by naming a registry key.

public function init()
{
    $this->_setAdapter('tdb');
}
+1
source

Source: https://habr.com/ru/post/1707814/


All Articles