Connect and Query MySQL Database
-
Hi there,
I am building a new WP site and want to create a couple of pages that access data from a separate mysql database. I want to insert the PHP into the pages using a plugin like Insert PHP.
I’ve installed the plugin but, I cannot seem to get the database to connect from within the WP page.
First off, I am not even sure where to put the second mysql file on the same server. It has a different login and PW than the WP site.
Should I put it in the \var\www\html folder? I don’t want to replace the DB I am using, just send some queries out to another one on the same server to get some data.
I’ve added PHP with the insert PHP plugin and I get an access denied message:
Connection failed: Access denied for user ‘root’@’localhost’
Here is the code I use:
$servername = “localhost”;
$username = “xxxx”;
$password = “xxxx”;
$dbname = “xxxx”;// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die(“Connection failed: ” . $conn->connect_error);
}
- The topic ‘Connect and Query MySQL Database’ is closed to new replies.