Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Set up the connection parameters
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "customers_app";
- // Create the connection
- $db = new mysqli($servername, $username, $password, $dbname);
- // Check to make sure it worked
- if ($db->connect_error) {
- die("Connection failed: " . $db->connect_error);
- }
- // Prepare and execute the SQL statement
- $sql = "SELECT Name, Country FROM customers";
- $result = $db->query($sql);
- // Create an array to store the results in temporarily
- $resultArray = array();
- // Put the resulting data into the
- while($row = $result->fetch_array(MYSQLI_ASSOC)) {
- $resultArray[] = $row;
- }
- // Encode the array as JSON and send it back
- echo json_encode($resultArray);
- // Close the connections
- $result->close();
- $db->close();
- ?>
Add Comment
Please, Sign In to add comment