Wordpress external DB connection error

admin

Administrator
Staff member
I have an external database I am trying to have a php page inside my WP connect to. If I go to the page directly outside of wordpress I see all the content from the DB displayed correctly.
If I look at the page inside of WP I get a DB connection error. Anyone know whats going on?

DB connection.php being included through a shortcode on a WP page.

Code:
<?php
// set database host
define ("DB_HOST", "www.example.com");
// set database user
define ("DB_USER", "user1");
// set database password
define ("DB_PASS","password1");
// set database name
define ("DB_NAME","databasename");

$link = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die('Could not make connection to DataBase: ' . mysql_error());

$db = mysql_select_db(DB_NAME, $link) or die('Could not select database: ' . mysql_error());
?>

Current output is a connection failor but again, when I look at the page in my browser outside of the WP page the connection is fine and all content is displayed.