<!DOCTYPE html>
<html>
<head>
    <title>Our first PHP + SQL program</title>
</head>
<body>
    <?php
    // Connect to the database.
    $hostname = "localhost";
    $username = "root";
    $password = ""; // WARNING: Under MAMP, it is "root"!
    $database_name = "ict_db";
    $link = mysqli_connect($hostname, $username, $password, $database_name);
    if(!$link) {
        // Could not connect !
        echo "<p>Problem while connecting to the SQL server.</p>\n";
        die;
    }
    
    // Create a request and process it.
    $request = "SELECT * FROM books;";
    $result = mysqli_query($link, $request);
    if (!$result) {
        echo "<p>Problem with request: " . mysqli_error($link) . ".</p>\n";
        die;
    }
    while ($line = mysqli_fetch_array($result)) {
        echo "<p>Book id " . $line['identifier'] . " is " . $line['title'] . " written by " . $line['author'] . ".</p>";
    }
    mysqli_free_result($result);
    
    // Close the connexion.
    mysqli_close($link);
    ?>
</body>
</html>