It's all about:
- adding an
i to the commands: mysql_query -> mysql
i_query
- adding the connection (e.g. "$con" to the command:
$con = mysqli_connect($host,$user,$pw) or die(mysql
i_error());
mysqli_select_db(
$con,$db) or die(mysqli_error());
mysqli_query(
$con,"SET CHARACTER SET utf8");
mysqli_query(
$con,"SET NAMES 'utf8'");
<?
$databasehost = "host";
$databasename = "db";
$databaseusername = "user";
$databasepassword = "pass";
$con = mysqli_connect($databasehost,$databaseusername,$databasepassword) or die(mysqli_error());
mysqli_select_db($con, $databasename) or die(mysqli_error());
mysqli_query($con, "SET CHARACTER SET utf8");
$query = file_get_contents("php://input");
$sth = mysqli_query($con, $query);
if (mysql_errno()) {
header("HTTP/1.1 500 Internal Server Error");
echo $query.'\n';
echo mysqli_error();
}
else
{
$rows = array();
while($r = mysqli_fetch_assoc($con, $sth)) {
$rows[] = $r;
}
print json_encode($rows);
}
?>