MySQL query is only showing information if I have a condition in the SQL statement.
I’ve successfully used the SQL statement in phpmyadmin and it works great. I’ve changed the table name in the PHP code and it functions properly, the “people” table is the only one that causes a problem.
<?php
include 'dbconnectLocal.php';
$sql = "SELECT * FROM people WHERE nameFirst = 'Karen'";
$billings = array();
$billingResults = mysqli_query($connL, $sql);
while($row = mysqli_fetch_assoc($billingResults)){
$billings[] = $row;
}
mysqli_close($connL);
$jsonOutput = json_encode($billings);
print("<pre>".json_encode($billings, JSON_PRETTY_PRINT)."</pre>");
?>
The above code produces the desired result, it gives me a JSON result of everyone whos name is Karen. But if I were to change it to $sql = “SELECT * FROM people” I get a blank screen.
2
Answers
After much digging around and frustration, it turned out to be a json_encode error. Specifically a UTF8 problem. Found this solution on php.net. I ran the array through this function before encoding it and it worked perfect.
Json have 4 mb limitation. You can make a var_dump of $billings to check what you get from db