Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $dbServername = 'localhost';
- $dbUsername = 'root';
- $dbPassword = '';
- $dbName = 'Friends';
- $conn = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);
- header('Content-Type: application/json');
- $sql = 'SELECT * FROM friends;';
- $result = mysqli_query($conn, $sql);
- $resultCheck = mysqli_num_rows($result);
- arr = [];
- if ($resultCheck > 0) {
- while ($row = mysqli_fetch_assoc($result)) {
- $arr[] = $row;
- }
- }
- echo json_encode($arr, JSON_PRETTY_PRINT);
- [{
- "id": "1",
- "name": "David Belton",
- "location": "Boston Celtics"
- }, {
- "id": "1",
- "name": "David Belton",
- "location": "Cleveland Cavaliers"
- }]
- {
- "id": "1",
- "name": "David Belton",
- "location": ["Boston Celtics", "Cleveland Cavaliers"]
- }
Add Comment
Please, Sign In to add comment