Php script not fetching mySQL data. Webpage displays [ ] symbol

时间:2019-04-17 01:33:59

标签: php json

My requirement is to create a JSON file using php script which fetches data from phpmyadmin server from a cpanel of a hosted website. The code works fine on local server xampp, but when I try to do that with a hosted server it doesn't work. It was working fine earlier. And after some time it stopped working without any code change and the webpage displays this symbol: [], whenever I tried accessing the file.

The webpage output: https://imgur.com/yy9Rsv2

The php file:

<?php
$host = "host";
$user_name = "username";
$password = "password";
$db_name = "u973124496";

    $con = mysqli_connect ($host,$user_name,$password,$db_name);
    $sql = "select * from stageone";
    $result = mysqli_query($con,$sql);
    $response = array();
    while($row=mysqli_fetch_array($result))
    {   array_push($response,array("id"=>$row["id"],"image_title"=>$row["image_title"],"image_from"=>$row["image_from"],"cover_photo"=>$row["cover_photo"],"main_photo"=>$row["main_photo"],"date"=>$row["date"],"tags"=>$row["tags"],"16:9"=>$row["16:9"],"18:9"=>$row["18:9"]));
    }
    echo json_encode($response);
    mysqli_close($con);
    ?>

I am looking for a JSON file which would fetch data from a mySQL database. Could someone help me fix this issue?

0 个答案:

没有答案