49 lines
1.2 KiB
PHP
49 lines
1.2 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
$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</h1>
|
|
|
|
<h2>Connecting to MySQL</h2>
|
|
|
|
<?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";
|
|
}
|
|
|
|
$conn = null;
|
|
?>
|
|
|
|
<h2>PHP Session Info</h2>
|
|
<?php
|
|
print_r($_SESSION);
|
|
?>
|
|
</body>
|
|
</html>
|