Fix utf8 and JSON issues resulting from MYSQL being weird

This commit is contained in:
Peder Bergebakken Sundt 2018-08-24 13:53:18 +02:00
parent 07c1a90845
commit d1612e2804
2 changed files with 13 additions and 2 deletions

View File

@ -28,7 +28,7 @@ class Doors{
}
public function getByName($name){
$query = 'SELECT * FROM doors WHERE name=:name';
$query = 'SELECT name, open, description FROM doors WHERE name=:name';
$statement = $this->pdo->prepare($query);
$statement->bindParam(':name', $name, PDO::PARAM_STR);
$statement->execute();

View File

@ -35,4 +35,15 @@ elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
}
}
echo json_encode($out);
function utf8ize($d) {
if (is_array($d)) {
foreach ($d as $k => $v) {
$d[$k] = utf8ize($v);
}
} else if (is_string ($d)) {
return utf8_encode($d);
}
return $d;
}
echo json_encode(utf8ize($out));