Guest User

Untitled

a guest
Mar 14th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. $dbServername = 'localhost';
  2. $dbUsername = 'root';
  3. $dbPassword = '';
  4. $dbName = 'Friends';
  5.  
  6. $conn = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);
  7.  
  8. header('Content-Type: application/json');
  9.  
  10. $sql = 'SELECT * FROM friends;';
  11. $result = mysqli_query($conn, $sql);
  12. $resultCheck = mysqli_num_rows($result);
  13.  
  14. arr = [];
  15.  
  16. if ($resultCheck > 0) {
  17. while ($row = mysqli_fetch_assoc($result)) {
  18. $arr[] = $row;
  19.  
  20. }
  21. }
  22.  
  23. echo json_encode($arr, JSON_PRETTY_PRINT);
  24.  
  25. [{
  26. "id": "1",
  27. "name": "David Belton",
  28. "location": "Boston Celtics"
  29. }, {
  30. "id": "1",
  31. "name": "David Belton",
  32. "location": "Cleveland Cavaliers"
  33. }]
  34.  
  35. {
  36. "id": "1",
  37. "name": "David Belton",
  38. "location": ["Boston Celtics", "Cleveland Cavaliers"]
  39. }
Add Comment
Please, Sign In to add comment