Major re-work of things...
This commit is contained in:
@@ -11,56 +11,54 @@
|
||||
|
||||
<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";
|
||||
echo '<pre>';
|
||||
echo "messageID\tdate\t\tsender\trecipient\tmessage\n\n";
|
||||
$sql_select = "SELECT messageID, date, sender, recipient, message";
|
||||
$sql_from = "FROM messages";
|
||||
$sql_where = "WHERE recipient='".$_SESSION["loggedInUser"]."' OR sender='".$_SESSION["loggedInUser"]."'";
|
||||
$sql_order = "ORDER BY messageID";
|
||||
$sql_statement = $sql_select." ".$sql_from." ".$sql_where." ".$sql_order;
|
||||
foreach($db_connection->query($sql_statement) as $row){
|
||||
print $row['messageID']."\t\t";
|
||||
print $row['date']."\t";
|
||||
print $row['message']."\t";
|
||||
print $row['sender']."\t";
|
||||
print $row['recipient']."\t\t";
|
||||
print $row['message']."\n";
|
||||
}
|
||||
echo '</pre>';
|
||||
}catch(PDOException $e){
|
||||
echo "PDOException: ".$e->getMessage().PHP_EOL;
|
||||
}catch(Exception $e){
|
||||
echo "Exception: ".$e->getMessage().PHP_EOL;
|
||||
}
|
||||
catch(Exception $e){
|
||||
echo "Error: ".$e->getMessage().PHP_EOL;
|
||||
}
|
||||
?>
|
||||
<h3>$sql</h3>
|
||||
<?php
|
||||
|
||||
echo '<h1>Variables</h1>';
|
||||
|
||||
echo '<h3>$sql</h3>';
|
||||
echo "<pre>";
|
||||
print_r($sql);
|
||||
echo "</pre>";
|
||||
?>
|
||||
|
||||
<h3>$_POST</h3>
|
||||
<?php
|
||||
echo "<pre>";
|
||||
print_r($_POST);
|
||||
echo "</pre>";
|
||||
?>
|
||||
$superglobalsList = array('$_SERVER','$_REQUEST','$_POST','$_GET','$_FILES','$_ENV','$_COOKIE','$_SESSION');
|
||||
foreach($superglobalsList as $value){
|
||||
echo "<h3>$value</h3>";
|
||||
echo '<pre>';
|
||||
print_r(eval('return '.$value.';'));
|
||||
echo '</pre>';
|
||||
}
|
||||
|
||||
<h3>$_SESSION</h3>
|
||||
<?php
|
||||
echo '<h2> Like, everything everything?...</h2>';
|
||||
echo '<h3>$GLOBALS</h3>';
|
||||
echo "<pre>";
|
||||
print_r($_SESSION);
|
||||
print_r($GLOBALS);
|
||||
echo "</pre>";
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<?php
|
||||
$connection = null;
|
||||
?>
|
||||
$db_connection = null;
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user