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

Connecting to remote MySQL database

Example code:
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:


XenForo developer
Staff member
You need to create a new database connection. Adjust this code to suit:
$db = Zend_Db::factory('mysqli',
        'host' => $config['db']['host'],
        'port' => $config['db']['port'],
        'username' => $config['db']['username'],
        'password' => $config['db']['password'],
        'dbname' => $config['db']['dbname'],
        'charset' => $config['db']['charset']