-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.php
43 lines (38 loc) · 1.03 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<!DOCTYPE html>
<html>
<head>
<title>MySQL Table Viewer</title>
</head>
<body>
<h1>MySQL Table Viewer</h1>
<?php
// Define database connection variables
$servername = "DBServer";
$username = "DB_USER";
$password = "DB_PASSWORD";
$dbname = "DB_NAME";
// Create database connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Query database for all rows in the table
$sql = "SELECT * FROM mytable";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// Display table headers
echo "<table><tr><th>ID</th><th>Name</th><th>Email</th></tr>";
// Loop through results and display each row in the table
while($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row["id"] . "</td><td>" . $row["name"] . "</td><td>" . $row["email"] . "</td></tr>";
}
echo "</table>";
} else {
echo "0 results";
}
// Close database connection
$conn->close();
?>
</body>
</html>