From what I can tell, PHP fails on building array with special character. Not sure where or why this is happening and how to solve.
function findRelated($subpass){
$subpass = "$subpass%";
global $mysqli;
if($stmt = $mysqli->prepare("SELECT pass FROM `passwords` WHERE pass LIKE ? LIMIT 500"))
{
$stmt->bind_param('s', $subpass);
if(!$stmt->execute())
{
$stmt->close();
return array("_status" => 3, "_msg" => "An error occured when executing your request");
}
if(!$result = $stmt->get_result())
{
return array("_status" => 3, "_msg" => "An error occured when executing your request");
}
while ($row = $result->fetch_assoc())
{
$rows[] = $row;
}
if(!empty($rows))
{
$stmt->close();
return array("_status" => 1, "_msg" => $rows);
}
else
{
$stmt->close();
return array("_status" => 2, "_msg" => "Your password was not found in the database.");
}
}
/* Close connection */
$stmt->close();
return array("_status" => 3, "_msg" => "Something is wrong with database connection");
}
This table has passwords that look like this: 'asdf', 'asdf 123', 'ASDF 12345', 'ASDF JKL ö'.
The last password: 'ASDF JKL ö' breaks something, most likely at the while loop or stmt->get_result, but it does not trigger an error. I just get an empty result back. Which means the while loop must have run at least once.
I've tried removing the 'ö' from the row, and it works like a charm. Changing 'ASDF JKL ö' to 'ASDF JKL '
I run the function with e.g. $result = findRelated('asdf');
Database has collation: latin1_swedish_ci. PHP and apache on Ubuntu runs with default config.
Thank you