Connecting to remote MySQL database

ItsHarry

Member
Example code:
PHP:
<?php
class Test_Callback {
 
    public static function testQuery(XenForo_ControllerPublic_Abstract $controller, XenForo_ControllerResponse_Abstract &$response) {
        $mydb = XenForo_Application::get('db');

        $testQuery = $mydb->fetchAll("
        SELECT username,avatar_date
        FROM `xf_user`
        WHERE `avatar_date` > 0
        ORDER BY `avatar_date` DESC");

        $response->params['testQuery'] = $testQuery;
    }
}

Simple question: How would I change it to connect to a remote MySQL database instead of the XF database?
 
Last edited:
You need to create a new database connection. Adjust this code to suit:
Code:
$db = Zend_Db::factory('mysqli',
    array(
        'host' => $config['db']['host'],
        'port' => $config['db']['port'],
        'username' => $config['db']['username'],
        'password' => $config['db']['password'],
        'dbname' => $config['db']['dbname'],
        'charset' => $config['db']['charset']
    )
);
 
Top Bottom