Using DataWriter for a table on another database

Cheesegrits

Active member
Is it possible to use the DataWriter to maintain a table on another database, i.e. a connection other than the one the XF tables reside on?

-- hugh
 
You can "inject" a own db connection to the datawriter
Create it:
PHP:
public static function db2Initialization(){
/** @var $instance XenForo_Application */
$instance = XenForo_Application::getInstance();
$instance->addLazyLoader('db2', array('Db2_Static', 'createSecondDbConnection'));
 
}
 
public static function createSecondDbConnection(){
 
$dbConfig = XenForo_Application::getConfig()->db2;
 
$instance = XenForo_Application::getInstance();
return $instance->loadDb($dbConfig);
 
}
Inject it:
PHP:
public function actionIndex(){
$db2 = XenForo_Application::get('db2');
$new = XenForo_DataWriter::create('Db2_DataWriter_Foo', XenForo_DataWriter::ERROR_ARRAY, array('db' => $db2));
$new->set('title', 'test');
 
Top Bottom