I have already seen many questions but nothing has helped. I want to convert my data from database (MySQL) to JSON using PHP. This is my PHP code:
init.php
<?php
$db_name = "webappdb";
$mysql_user = "root";
$mysql_pass = "root";
$server_name = "localhost";
$charset= "utf8";
$con = mysqli_connect($charset, $server_name, $mysql_user, $mysql_pass, $db_name);
?>
listViewBooks.php
<?php
include("init.php");
header('Content-Type: application/json');
// get all items from user_info_book table
$sql = mysqli_query("SELECT * FROM `user_info_book`");
$res = mysqli_query($con,$sql);
$result = array();
while($row = mysqli_fetch_array($res)){
$output[] = $row;
}
echo json_encode($output);
echo json_last_error();
mysqli_close($con);
?>
The error is 0
, so it's nothing.