My PHP/HTML code below displays data from a database on a website, refreshing it every few seconds in order to have the most up-to-date information. Is it possible to kill the database connection five minutes after the link to this website was clicked? The fields for the database connection are left blank for my own privacy. Could somebody show in my code how I would include this? Thanks
<HTML>
<head>
<meta http-equiv="refresh" content="2">
</head>
</html>
<?php
$db = mysqli_connect('', '', '', '') or die('Error connecting to MySQL server.');
?>
<?php
$servername = "";
$username = "";
$password = "";
$database = "";
if (mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$conn = new mysqli($servername, $username, $password, $database);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if(mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($db, "SELECT * FROM patients2");
echo "<table border = 5>";
echo "<tr>";
echo "<th>ID</th> <th>Patient name</th>
<th>Doctor name</th>
<th>Check in date</th>
<th>Room number</th>
<th>Bed number</th>
<th>Notes</th>
<th>Time</th>";
echo "</tr>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['patient_name'] . "</td>";
echo "<td>" . $row['doctor_name'] . "</td>";
echo "<td>" . $row['check_in_date'] . "</td>";
echo "<td>" . $row['room_number'] . "</td>";
echo "<td>" . $row['bed_number'] . "</td>";
echo "<td>" . $row['notes'] . "</td>";
echo "<td>" . $row['time'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($db);
?>