41 lines
1.0 KiB
PHP
41 lines
1.0 KiB
PHP
<?php
|
|
$server = "localhost";
|
|
$database = "friendBook";
|
|
$username = "web";
|
|
$password = "Password456";
|
|
|
|
// Current user
|
|
$user = "William"; // Testing with until we have login working
|
|
?>
|
|
|
|
<html>
|
|
<head>
|
|
</head>
|
|
<body>
|
|
<h1>PHP Test Page - Connecting to MySQL</h1>
|
|
|
|
<?php
|
|
try{
|
|
$connection = new PDO("mysql:host=$server;dbname=$database", $username, $password);
|
|
// set the PDO error mode to exception
|
|
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
echo "Connected successfully";
|
|
}
|
|
catch(PDOException $e){
|
|
echo "Connection failed: " . $e->getMessage();
|
|
}
|
|
|
|
$sql = "SELECT messageID, date, message
|
|
FROM messages
|
|
WHERE recipient=$user";
|
|
foreach($connection->query($sql) as $row){
|
|
print $row['messageID'] . "\t";
|
|
print $row['date'] . "\t";
|
|
print $row['message'] . "\t";
|
|
}
|
|
|
|
mysqli_close($connection);
|
|
?>
|
|
|
|
</body>
|
|
</html>
|