简体   繁体   中英

getting blank json response while fetching images url from database via php api

Code to fetch all images from server . I am saving the url of the images present in my server path/directory to the SQL database (name : photos , columns :id and image )

<?php

     $connection = mysqli_connect("localhost","webkuv1c_naman","naman","webkuv1c_android_api") or die("Error " . mysqli_error($connection));
     $sql = "select image from photos";
     $res = mysqli_query($con,$sql);
     $result = array();

     while($row = mysqli_fetch_array($res)){
         array_push($result,array('url'=>$row['image']));
     }

     echo json_encode(array("result"=>$result));

     mysqli_close($con);
?>

I am getting following response on hitting API :

{"result":[]}

this is the image path/url : http://webkunj.com/android_api/productUpload/0.png

You have made all things properly just replace

$connection = mysqli_connect("localhost","webkuv1c_naman","naman","webkuv1c_android_api") or die("Error " . mysqli_error($connection));

with

 $con = mysqli_connect("localhost","webkuv1c_naman","naman","webkuv1c_android_api") or die("Error " . mysqli_error($con));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM