Write Api in php

Loading

Code of index_webservice.php file is below

 

<?php
$conn =new mysqli('localhost', 'root', '' , 'suman');

$sql = "SELECT id,name,email FROM student";
$result = $conn->query($sql);
$i=0;
while($arr = $result -> fetch_array())
{
$arr_new[$i]['id']=$arr['id'];
$arr_new[$i]['name']=$arr['name'];
$arr_new[$i]['email']=$arr['email'];
$i++;
}
$result -> free_result();
$conn->close();

echo json_encode(array('data'=>$arr_new));
?>

Manipulate database table and create a array.Then pass it into json_encode() function.You are one the way!

url: http://localhost/suman/index_webservice.php


0 0 votes
Article Rating
Subscribe
Notify of

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x