-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetUsers.php
More file actions
37 lines (29 loc) · 1009 Bytes
/
getUsers.php
File metadata and controls
37 lines (29 loc) · 1009 Bytes
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
<?php
//See original: https://www.w3schools.com/php/php_mysql_connect.asp
$servername = "localhost";
$username = "root";
$password = "";
$dbName = "chatLog";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbName", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully <br>";
$getUsers = "SELECT username, firstName, lastName FROM users";
$statement = $conn -> query($getUsers);
//display table of results
print "<style> table, th, td {border: 1px solid black;} </style>";
print "<table><tr><th>Username</th><th>First Name</th><th>Last Name</th></tr>";
foreach ($statement as $row) {
print "<tr>";
print "<td>" . $row['username'] . "</td>";
print "<td>" . $row['firstName'] . "</td>";
print "<td>" . $row['lastName'] . "</td>";
print "</tr>";
}
print "</table>";
}
catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
?>