This query below on localhost (PHP/5.4.22)
<?php
global $db;
$query = $db->query("SELECT * FROM player WHERE playerID = '181783'") or die(mysqli_error($db));
foreach ($query as $row) {
$fName = $row['fName'];
echo "First Name: " . $fName;
}
?>
How ever on my webhost (PHP/5.3.28)
this query returns
First Name: First Name: First Name: First Name: First Name:
There is currently only 1 result that returns where playerID = 181783, and it should echo the name 'Mario'
When I run the query like below on my webhost it works and echos Mario.
$query2 = $db->query("SELECT * FROM player WHERE playerID = '181783'");
$result = $query2->fetch_object();
echo $result->fName;
So this must mean the db connection is set up correctly, as query2 is on the same page and working, just for some reason with query one it doesn't echo the result, but shows 'First Name:' 5 times.
It is like this for all foreach() functions I have used throughout my site, so I cannot just query 2.
To summaries, both queries work on localhost, when uploading to my webhost only query 2 works.
There are no errors despite error_reporting(E_ALL); being enabled
What should I do? Thanks.
Edit- db config
//MySQLI configuration
$_CONFIG['mysql']['hostname'] = 'localhost';
$_CONFIG['mysql']['username'] = '#';
$_CONFIG['mysql']['password'] = '#';
$_CONFIG['mysql']['database'] = '#';
//Initialize MySQLi connection
$db = new mysqli($_CONFIG['mysql']['hostname'], $_CONFIG['mysql']['username'], $_CONFIG['mysql']['password'], $_CONFIG['mysql']['database']);
if ($db->connect_errno) {
die("MySQLi error: ".$db->connect_error);
}