Made $db global

This commit is contained in:
Lars van Hijfte
2017-01-19 11:57:54 +01:00
parent b71cf36798
commit 186cdf1445
14 changed files with 58 additions and 79 deletions

View File

@@ -1,14 +1,9 @@
<?php
require_once("connect.php");
session_start();
function getOldChatMessages($user2ID) {
$db = $GLOBALS["db"];
$user1ID = $_SESSION["userID"];
$stmt = $db->prepare("
$stmt = $GLOBALS["db"]->prepare("
SELECT
*
FROM
@@ -31,8 +26,7 @@ function getOldChatMessages($user2ID) {
}
function sendMessage($destination, $content) {
$db = $GLOBALS["db"];
$stmt = $db->prepare("
$stmt = $GLOBALS["db"]->prepare("
INSERT INTO
`private_message`
(
@@ -56,10 +50,7 @@ function sendMessage($destination, $content) {
}
function getNewChatMessages($lastID, $destination) {
$db = $GLOBALS["db"];
$origin = $_SESSION["userID"];
$stmt = $db->prepare("
$stmt = $GLOBALS["db"]->prepare("
SELECT
*
FROM
@@ -75,11 +66,11 @@ function getNewChatMessages($lastID, $destination) {
`messageID` ASC
");
$stmt->bindParam(':user1', $origin);
$stmt->bindParam(':user1', $_SESSION["userID"]);
$stmt->bindParam(':user2', $destination);
$stmt->bindParam(':lastID', $lastID);
$stmt->execute();
return json_encode($stmt->fetchAll());
}
}