Merge branch 'lars-algemeen' into 'master'

Lars algemeen

See merge request !51
This commit was merged in pull request #55.
This commit is contained in:
Marijn Jansen
2017-01-17 12:49:29 +01:00
6 changed files with 67 additions and 14 deletions

View File

@@ -1,14 +0,0 @@
<?php
$servername = "agile136.science.uva.nl";
$username = "mhbp";
$password = "qdtboXhCHJyL2szC";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>

7
website/mysql_config.xml Normal file
View File

@@ -0,0 +1,7 @@
<?xml version='1.0'?>
<MySQL_INIT>
<mysql_host>localhost</mysql_host>
<mysql_database>myhyvesbookplus</mysql_database>
<mysql_username>mhbp</mysql_username>
<mysql_password>qdtboXhCHJyL2szC</mysql_password>
</MySQL_INIT>

View File

@@ -0,0 +1,18 @@
<html>
<head>
</head>
<body>
<?php
// database gegevens zijn elders opgeslagen
include_once("../queries/connect.php");
include_once("../queries/friendship.php");
$friends = selectAllFriends($db, 666);
while($friend = $friends->fetch(PDO::FETCH_ASSOC)) {
echo $friend['username'].' '.$friend['onlinestatus'] . "<br />";
}
?>
</body>
</html>

View File

@@ -0,0 +1,13 @@
<?php
$dbconf = simplexml_load_file("/var/mysql_config.xml");
if ($dbconf === FALSE) {
die("Error parsing XML file");
}
else {
$db = new PDO("mysql:host=$dbconf->mysql_host;dbname=$dbconf->mysql_database;charset=utf8",
"$dbconf->mysql_username", "$dbconf->mysql_password")
or die('Error connecting to mysql server');
}
?>

View File

@@ -0,0 +1,24 @@
<?php
function selectAllFriends($db, $userID) {
return $db->query("
SELECT
`user`.`username`,
`user`.`profilepicture`,
`user`.`onlinestatus`,
`user`.`role`
FROM
`user`
INNER JOIN
`friendship`
WHERE
`friendship`.`user1ID` = $userID AND
`friendship`.`user2ID` = `user`.`userID` OR
`friendship`.`user2ID` = $userID AND
`friendship`.`user1ID` = `user`.`userID`"
);
}
?>

View File

@@ -13,3 +13,8 @@
@import url("styles/menu.css"); @import url("styles/menu.css");
@import url("styles/footer.css"); @import url("styles/footer.css");
</style> </style>
<?php
include_once("../connect.php");
?>