63 lines
1.6 KiB
PHP
63 lines
1.6 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
$server = "localhost";
|
|
$database = "friendBook";
|
|
$username = "web";
|
|
$password = "Password456";
|
|
?>
|
|
|
|
<html>
|
|
<head>
|
|
</head>
|
|
<body>
|
|
<h1>PHP Test Page</h1>
|
|
|
|
<h2>MySQL</h2>
|
|
|
|
<h3>Creating Connection</h3>
|
|
<?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".PHP_EOL;
|
|
}
|
|
catch(PDOException $e){
|
|
echo "Connection failed: ".$e->getMessage().PHP_EOL;
|
|
}
|
|
?>
|
|
|
|
<h3>Creating and Executing Query</h3>
|
|
<?php
|
|
try{
|
|
$sql = "SELECT messageID, date, message FROM messages WHERE recipient={$_SESSION["loggedInUser"]}";
|
|
foreach($connection->query($sql) as $row){
|
|
print $row['messageID']."\t";
|
|
print $row['date']."\t";
|
|
print $row['message']."\t";
|
|
}
|
|
}
|
|
catch(Exception $e){
|
|
echo "Error: ".$e->getMessage().PHP_EOL;
|
|
}
|
|
?>
|
|
<h3>$sql</h3>
|
|
<?php
|
|
echo "<pre>";
|
|
print_r($sql);
|
|
echo "</pre>";
|
|
?>
|
|
|
|
<h3>$_SESSION</h3>
|
|
<?php
|
|
echo "<pre>";
|
|
print_r($_SESSION);
|
|
echo "</pre>";
|
|
?>
|
|
</body>
|
|
</html>
|
|
|
|
<?php
|
|
$connection = null;
|
|
?>
|