My first post here!
I wrote a job management portal for a client about 6 years ago and it hasn't really been updated at all since then. Yesterday it sort of stopped working and the shared hosting provider states no updates had been performed on their server to kill it. I narrowed it down to all of the database queries failing if they don't have bind parameters but they work if they do have bind parameters. Weird. Here is a simple script I wrote to show what's happening:
<?php
$mysqli_connection = new MySQLi('localhost', '********', '******', '*********');
if ($mysqli_connection->connect_error) {
echo "Not connected, error: " . $mysqli_connection->connect_error;
}
else {
echo "Connected<br />";
}
// this returns nothing
if($stmt = $mysqli_connection->prepare("SELECT id FROM users where username = 'dan'"))
{
$username = 'dan';
// $stmt -> bind_param("s", $username);
$stmt -> execute();
$stmt->store_result();
$stmt -> bind_result($user_id);
while ($stmt -> fetch())
echo "result1: " . $user_id . "<br />";
$stmt->close();
}
// this returns 1 (the ID)
if($stmt = $mysqli_connection->prepare("SELECT id FROM users WHERE username = ?"))
{
$username = 'dan';
$stmt -> bind_param("s", $username);
$stmt -> execute();
$stmt->store_result();
$stmt -> bind_result($user_id);
while ($stmt -> fetch())
echo "result2: " . $user_id . "<br />";
$stmt->close();
}
// They should both output the ID, why is the first one failing?
?>
I moved the entire site over to my AWS EC2 server and it worked fine, it only fails like this on the shared hosting server where it currently resides. Does anyone know why or how this is possible? I've never seen anything like this before.