0

I have used this same code before and it worked fine, but now that I have changed of host provider it doesn't. The connection is fine and fetching is correct. I've already checked line by line the code and everything seems to point that the problem is in the encode, but I can't figure out why.

$res=$cnx->query("SELECT U_ID, NAME FROM `USERS`;");

jsonData = array();

while ($array = $res -> fetch(PDO::FETCH_ASSOC)) 
{
    $jsonData[] = $array;
}
echo json_encode(array('USERS' => $jsonData), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);

It returns nothing, just a white line of nothing

  • 2
    var_dump($jsonData)? – LF00 Jan 20 '17 at 04:06
  • 1
    You should make sure that every component of your web application uses UTF-8. http://stackoverflow.com/questions/32672720/json-encode-not-returning-anything – channasmcs Jan 20 '17 at 04:09
  • 1
    @KrisRoofe Normally that would work, but when `json_encode` fails it simply returns `false`. You need `json_last_error_msg()` here – Machavity Jan 20 '17 at 04:11
  • My personal bet is your DB isn't UTF-8. It's the most common problem here, hands down. If I were you, I'd read through [this question](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through) and make sure you have solid UTF-8 – Machavity Jan 20 '17 at 04:14

0 Answers0