I have simple php script that shoud output json, but it dont work
<?php
require 'connect.php';
$sql = "SELECT * FROM horizont";
$result = $con->query($sql);
$rows = array();
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$rows[] = $row;
}
}
echo '<pre>';
var_dump($rows);
echo '</pre>';
echo json_encode($rows);
?>
i get result on var dump , but not json code.
var dump result:
connect.php
<?php
$con = mysqli_connect("localhost","root","","horizont");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
Fixed with :
$con->set_charset("utf8");