index.php
php1 kB51 linesIn php-student-app.zip
php-student-app.zipindex.php
<?php
// Database configuration
$host = "in401-db.cd0ca4e6uj74.eu-central-1.rds.amazonaws.com";
$port = 3306;
$database = "lab_example";
$username = "admin";
$password = "in401pass";
// Connect to MySQL database
try {
$conn = new PDO("mysql:host=$host;port=$port;dbname=$database", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Query to fetch all students
$stmt = $conn->query("SELECT * FROM students");
$students = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch(PDOException $e) {
die("Connection failed: " . $e->getMessage());
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Student List</title>
</head>
<body>
<?php if (count($students) > 0): ?>
<table>
<tr>
<th>ID</th>
<th>Full Name</th>
<th>Email</th>
<th>Major</th>
<th>Created At</th>
</tr>
<?php foreach ($students as $student): ?>
<tr>
<td><?php echo $student['id']; ?></td>
<td><?php echo $student['full_name']; ?></td>
<td><?php echo $student['email']; ?></td>
<td><?php echo $student['major']; ?></td>
<td><?php echo $student['created_at']; ?></td>
</tr>
<?php endforeach; ?>
</table>
<?php else: ?>
<p>No students found in the database.</p>
<?php endif; ?>
</body>
</html>