<?php

header('Content-Type: text/json');

require_once('config.php');

$mysqli = new mysqli('localhost', 'ajax_course', 'ajax_course', 'ajax_course');

$query = 'SELECT book_id, book_title FROM books';

$result = $mysqli->query($query);

$books = array();

while($row = $result->fetch_array(MYSQLI_ASSOC)) {
	$book_id = $row['book_id'];
	$book_title = $row['book_title'];
	
	$book = array('title' => $book_title, 'id' => $book_id);
	
	array_push($books, $book);
}

$response = array('books' => $books);

echo json_encode($response);

$result->close();
$mysqli->close();

?>