Advertisement
payen83

JSON Retrieve Data NEW

Dec 4th, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1.  
  2. <?php
  3.  
  4. //view list of persons in db
  5.  
  6. $user = 'username';
  7. $password = 'password';
  8. $db = 'dbname';
  9. $host = 'localhost';
  10.  
  11.  
  12. //open connection to mysql db
  13. $connection = mysqli_connect($host,$user,$password,$db) or die("Error " . mysqli_error($connection));
  14.  
  15. //fetch table rows from mysql db
  16.  
  17. $sql = "select * from staff";
  18. $result = mysqli_query($connection, $sql) or die("Error in Selecting " . mysqli_error($connection));
  19.  
  20. //create an array
  21. $emparray = array();
  22. while($row =mysqli_fetch_assoc($result))
  23. {
  24. $emparray['person'][] = $row;
  25. }
  26. echo json_encode($emparray);
  27.  
  28. //close the db connection
  29. mysqli_close($connection);
  30.  
  31. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement