1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Using DataWriter for a table on another database

Discussion in 'XenForo Development Discussions' started by Cheesegrits, Apr 29, 2013.

  1. Cheesegrits

    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
     
  2. xf_phantom

    xf_phantom Well-Known Member

    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');
     
  3. Cheesegrits

    Cheesegrits Active Member

    Perfect!

    Thank you.

    -- hugh
     

Share This Page