0

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:

http://prntscr.com/e0ef2c

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");
marko marinovic
  • 103
  • 1
  • 9

1 Answers1

2

For encoding problem try this:

$con->set_charset("utf8");
mwweb
  • 7,625
  • 4
  • 19
  • 24