Guest User

Untitled

a guest
Apr 27th, 2017
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. <?php
  2. // Set up the connection parameters
  3. $servername = "localhost";
  4. $username = "root";
  5. $password = "";
  6. $dbname = "customers_app";
  7.  
  8. // Create the connection
  9. $db = new mysqli($servername, $username, $password, $dbname);
  10.  
  11. // Check to make sure it worked
  12. if ($db->connect_error) {
  13. die("Connection failed: " . $db->connect_error);
  14. }
  15.  
  16. // Prepare and execute the SQL statement
  17. $sql = "SELECT Name, Country FROM customers";
  18. $result = $db->query($sql);
  19.  
  20. // Create an array to store the results in temporarily
  21. $resultArray = array();
  22.  
  23. // Put the resulting data into the
  24. while($row = $result->fetch_array(MYSQLI_ASSOC)) {
  25. $resultArray[] = $row;
  26. }
  27.  
  28. // Encode the array as JSON and send it back
  29. echo json_encode($resultArray);
  30.  
  31. // Close the connections
  32. $result->close();
  33. $db->close();
  34. ?>
Add Comment
Please, Sign In to add comment