connect_error) { die("Connection failed: " . $conn->connect_error); } // SQL query $sql = "SELECT id, firstname, lastname FROM MyGuests"; $result = $conn->query($sql); if ($result->num_rows > 0) { // Output data of each row while($row = $result->fetch_assoc()) { echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "In this example, a connection to a MySQL database is established, and a query is made to retrieve data from the table "MyGuests". The results are then displayed on the webpage. Package library: MySQLi. This library provides an object-oriented interface for accessing MySQL databases from PHP.
"; } } else { echo "0 results"; } $conn->close(); ?>