Mysqli query only works on localhost, not webserver
- by whamo
Hello.
I have changed some of my old queries to the Mysqli framework to improve performance. Everything works fine on localhost but when i upload it to the webserver it outputs nothing. After connecting I check for errors and there are none. I also checked the php modules installed and mysqli is enabled.
I am certain that it creates a connection to the database as no errors are displayed. (when i changed the database name string it gave the error)
There is no output from the query on the webserver, which looks like this:
$mysqli = new mysqli("server", "user", "password");
if (mysqli_connect_errno()) {
printf("Can't connect Errorcode: %s\n", mysqli_connect_error());
exit;
}
// Query used
$query = "SELECT name FROM users WHERE id = ?";
if ($stmt = $mysqli->prepare("$query"))
{
// Specify parameters to replace '?'
$stmt->bind_param("d", $id);
$stmt->execute();
// bind variables to prepared statement
$stmt->bind_result($_userName);
while ($stmt->fetch())
{
echo $_userName;
}
$stmt-close();
}
}
//close connection
$mysqli-close();
As I said this code works perfectly on my localserver just not online. Checked the error logs and there is nothing so everything points to a good connection. All the tables exists as well etc. Anyone any ideas because this one has me stuck! Also, if i get this working, will all my other queries still work? Or will i need to make them use the mysqli framework as well? Thanks in advance.