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

Mysql connect to second database

Discussion in 'XenForo Development Discussions' started by AndyB, Sep 9, 2016.

  1. AndyB

    AndyB Well-Known Member

    I have an add-on in which I'm trying to connect to a second database. Why is this PHP code not working?

    PHP:
    $db Zend_Db::factory('mysqli',
        array(
        
    'host' => $config['db']['localhost'],
        
    'port' => $config['db']['3306'],
        
    'username' => $config['db']['XXX'],
        
    'password' => $config['db']['XXX'],
        
    'dbname' => $config['db']['XXX']
        )
    );

    $db->getConnection();
    I get the following error:

    Access denied for user ''@'localhost' (using password: NO)
     
  2. AndyB

    AndyB Well-Known Member

    The server error log shows this:

    Code:
    ErrorException: Undefined variable: config - library/Andy/InternalDataCheck/ControllerPublic/InternalDataCheck.php:32
    Generated By: AndyB, 3 minutes ago
    
     
  3. AndyB

    AndyB Well-Known Member

    Got it:

    PHP:
    $db Zend_Db::factory('mysqli',
        array(
        
    'host' => 'localhost',
        
    'port' => '3306',
        
    'username' => 'XXX',
        
    'password' => 'XXX',
        
    'dbname' => 'XXX'
        
    )
    );

    $db->getConnection();
     
    Earl likes this.

Share This Page