1. 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

Discussion in 'XenForo Development Discussions' started by ItsHarry, Sep 3, 2016.

  1. ItsHarry

    ItsHarry Member

    Example code:
    class Test_Callback {
        public static function 
    testQuery(XenForo_ControllerPublic_Abstract $controllerXenForo_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: Sep 3, 2016
  2. Mike

    Mike 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']
    Thomas.B likes this.
  3. ItsHarry

    ItsHarry Member

    Thank you, it works beautifully

Share This Page