How to connect to remote database on WordPress

Probably been covered but I keep getting “connecting to the WordPress database” which isn’t what I’m after. In a nutshell I have a perfectly fine WordPress site, I also have a MySQL database on another server which has some data I’m after. The code works fine on phpfiddle (is this the standard?) but whenever I try to use it on the WordPress site, either with shortcodes or in the header.php it keeps hanging, throwing errors and won’t connect to the DB, any ideas why?

Edit: To make things clearer, it’s a meteorological database I want to connect to in order to pull things like Temperature from. Nothing native or related to WordPress.

Read More
<?php
// Create connection
$con=mysqli_connect("ip","user","pass","db");

// Check connection
if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

mysqli_close($con);
?>

Gives me this

Warning: mysqli_connect(): (HY000/2003): Can't connect to MySQL server on...

Related posts

Leave a Reply

2 comments