I am trying to connect to a database in the function.php using mysqli. The code seems to run fine when it is not on a separate php file not on wordpress. But when I run it on wordpress I get "Connect failed: No connection could be made because the target machine actively refused it." I am not sure if wordpress is preventing this. So can someone enlighten me on this problem?
Code is provided below if needed.
require_once($_SERVER['DOCUMENT_ROOT'] . '/forum/config.php');
$mysqli = new mysqli($dbhost,$dbuser,$dbpasswd,$dbname);
if ($mysqli->connect_errno)
{
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
$data = '<?xml version="1.0"?>
<!-- squad info -->
<squad nick="DC">
<name>Dog Company</name>
<email>n/a@gmail.com</email>
<web> http://www.dog-company.com</web>
<picture>sqd_logo.paa</picture>
<title>Dog Company</title>
<!-- start of member list/info -->
<!-- Updated users and updated to xml on server-->';
$query = 'SELECT *
FROM '.$table_prefix.'users u
LEFT JOIN '.$table_prefix.'profile_fields_data f
ON (u.user_id = f.user_id)
LEFT JOIN '.$table_prefix.'user_group g
ON (u.user_id = g.user_id)
WHERE g.group_id = 9';
if ($result = $mysqli->query($query)) {
/* fetch associative array */
while ($row = $result->fetch_assoc()) {
if($row['pf_xml_arma_id'] != ""){
$data .= '<member id="'.$row['pf_xml_arma_id'].'" nick="'.$row['pf_xml_player_name'].'">';
$name = ($row['pf_xml_name'] == '' ? "N/A" : $row['pf_xml_name']);
$email = ($row['pf_xml_email'] == '' ? "N/A" : $row['pf_xml_email']);
$steam = ($row['pf_xml_steam_user'] == '' ? "N/A" : "Steam: ".$row['pf_xml_steam_user']);
$quote = ($row['pf_xml_remark'] == '' ? "N/A" : $row['pf_xml_remark']);
$data .= '<name>'.$name.'</name>
<email>'.$email.'</email>
<icq>'.$steam.'</icq>
<remark>'.$quote.'</remark>';
$data .= '</member>';
}
}
/* free result set */
$result->free();
}
/* close connection */
$mysqli->close();
$data .= '</squad>';
return $data;
Thank you for your time,
UPDATE
Seems like my $query wasn't getting the $table_prefix from my config file. I am not sure why it cannot access it though. Anyone?
wpdb
instances