Skip to content

Instantly share code, notes, and snippets.

@thelazyindian
Created July 10, 2017 13:11
Show Gist options
  • Save thelazyindian/d4e6db7b09e8d2a9b47e3c40a83fec87 to your computer and use it in GitHub Desktop.
Save thelazyindian/d4e6db7b09e8d2a9b47e3c40a83fec87 to your computer and use it in GitHub Desktop.
<?php
//open connection to mysql db
$connection = mysqli_connect("localhost","root","","students") or die("Error " . mysqli_error($connection));
//fetch table rows from mysql db
$sql = "select * from name";
$result = mysqli_query($connection, $sql) or die("Error in Selecting " . mysqli_error($connection));
//create an array
$emparray = array();
while($row =mysqli_fetch_assoc($result))
{
$emparray[] = $row;
}
echo json_encode($emparray);
//close the db connection
mysqli_close($connection);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment