Note that there are some explanatory texts on larger screens.

plurals
  1. POZend_Db_Table Using different Connection-Adapter for reading and writing
    primarykey
    data
    text
    <p>In a current ZF project i have to use diffrent DB Connections for reading and writing. My approuch was do this by extending Zend_Db_Table_Abstract (and Zend_Db_Table_Row_Abstract)</p> <p>It looks like this at the moment:</p> <pre><code>class SomeNamespace_Db_Table extends Zend_Db_Table_Abstract { /** * @var Zend_Db */ protected $read = NULL; /** * @var Zend_Db */ protected $write = NULL; /** * Constructor. * * Supported params for $config are: * - db = user-supplied instance of database connector, * or key name of registry instance. * - name = table name. * - primary = string or array of primary key(s). * - rowClass = row class name. * - rowsetClass = rowset class name. * - referenceMap = array structure to declare relationship * to parent tables. * - dependentTables = array of child tables. * - metadataCache = cache for information from adapter describeTable(). * * @param mixed $config Array of user-specified config options, or just the Db Adapter. * @return void */ public function __construct($config=array()){ $this-&gt;read = Zend_Registry::get('read'); $this-&gt;write = Zend_Registry::get('write'); $config['db'] = $this-&gt;read; return parent::__construct($config); } /** * Inserts a new row. * * @param array $data Column-value pairs. * @return mixed The primary key of the row inserted. */ public function insert(array $data){ $this-&gt;setAdapter($this-&gt;write); $result = parent::insert($data); $this-&gt;setAdapter($this-&gt;read); return $result; } /** * Updates existing rows. * * @param array $data Column-value pairs. * @param array|string $where An SQL WHERE clause, or an array of SQL WHERE clauses. * @return int The number of rows updated. */ public function update(array $data, $where){ $this-&gt;setAdapter($this-&gt;write); $result = parent::update($data,$where); $this-&gt;setAdapter($this-&gt;read); return $result; } /** * Fetches a new blank row (not from the database). * * @param array $data OPTIONAL data to populate in the new row. * @param string $defaultSource OPTIONAL flag to force default values into new row * @return Zend_Db_Table_Row_Abstract */ public function createRow(array $data = array(), $defaultSource = NULL){ $this-&gt;setAdapter($this-&gt;write); $result = parent::createRow($data, $defaultSource); $this-&gt;setAdapter($this-&gt;read); return $result; } /** * Deletes existing rows. * * @param array|string $where SQL WHERE clause(s). * @return int The number of rows deleted. */ public function delete($where){ $this-&gt;setAdapter($this-&gt;write); $result = parent::delete($where); $this-&gt;setAdapter($this-&gt;read); return $result; } /** * Allow to set current used connection * from Enalog_Db_Table_Row * * @param Zend_Db $db */ public function setAdapter($db){ $this-&gt;_db = self::_setupAdapter($db); return $this; } </code></pre> <p>}</p> <p>For my liking this is way to much redundant code. (In Zend_Db_Table_Row i will also have to overwrite the save and setFromArray methods)</p> <p>Any suggestions on this ? The switching between the two DB Connections should be as transparent as possible.</p> <p>TIA Rufinus</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload