Connect Second Database to WordPress

I have found that the following works for connecting the database via the theme’s functions.php file. I placed this code snippet at the end of the existing code in the file. Even though the fatal error threw several line errors when trying to access the site, it only came down to wpdb having an extra d in it. This code now properly connects the secondary database with no errors. When using this, please remember to replace the information in parenthesis with the correct information applicable to the secondary database that you are trying to connect to the site.

    function seconddb() {
             global $seconddb;
             $seconddb = new 
             wpdb('Username','password','database name','localhost');
    }
    add_action('init','seconddb');