The Problem
I have a db.php
file which contains mysql login details. I want it in a separate file like this so it can be linked in several different pages for easier tracing later.
This all works when not on a wordpress site, but I'm trying to convert everything over to wordpress now and I'm encountering a problem.
The below doesn't work (echoes nothing on page), but if I copy the single line from inc/db.php
into my page-pricechanges.php
it works.
What's the best way for me to link this?
Structure
\THEMEFOLDER
- \page-pricechanges.php
- \header-pricechanges.php
- \inc\db.php
Page code
header-pricechanges.php
<head>
<?php
include 'inc/db.php';
//I have also tried include get_bloginfo("template_url")'/inc/db.php';
//I have tried include 'db.php' and put db.php in root of site, root of theme folder.. nothing seems to pick it up.
?>
</head>
inc/db.php
<?php
$con=mysqli_connect("localhost","root","", "dbname");
?>
page-pricechanges.php
$query1 = mysqli_query($con, "SELECT * FROM dbname ORDER BY balance DESC")
or die(mysql_error());
while ($row = mysqli_fetch_assoc($query1))
{
$id = $row['id'];
$name = addslashes($row['name']);
echo $id." ".$name."<br>";
}