<?
php
// Connect to the database
$conn = mysqli_connect("localhost", "username", "password", "student_database");
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// Retrieve data from the database
$sql = "SELECT * FROM students";
$result = mysqli_query($conn, $sql);
// Check if there are any results
if (mysqli_num_rows($result) > 0) {
// Output data of each row
echo "<h2>Student Data:</h2>";
echo "<table border='1'>";
echo "<tr><th>ID</th><th>Name</th><th>Age</th></tr>";
while ($row = mysqli_fetch_assoc($result)) {
echo
"<tr><td>".$row["id"]."</td><td>".$row["name"]."</td><td>".$row["age"]."</td></tr>";
}
echo "</table>";
} else {
echo "No records found";
}
// Close connection
mysqli_close($conn);
?>