Begin with the connection between php and mysql.

It has a template that loads all the friends of userID 666.
It uses a connect.php and a friendship.php
This commit is contained in:
Lars van Hijfte
2017-01-17 12:48:01 +01:00
parent ff2927755d
commit 10d3e177ae
6 changed files with 67 additions and 14 deletions

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`"
);
}
?>