private function countNoteTakers() { $db = GetDatabaseConnection(); $pdo = $db->prepare("SELECT COUNT(*) FROM NoteTakers"); $pdo->execute(); return $pdo->fetch(PDO::FETCH_NUM)[0]; }
private function getNoteCollectionId($noteTakerGuid, $noteCollectionGuid) { $db = GetDatabaseConnection(); $pdo = $db->prepare("SELECT NoteCollections.Id as Id FROM NoteCollections\n INNER JOIN NoteTakerNoteCollectionRelations as relation ON relation.NoteCollectionId = NoteCollections.Id\n INNER JOIN NoteTakers as taker ON relation.NoteTakerId = taker.Id\n WHERE taker.Guid = :NoteTakerGuid AND NoteCollections.Guid = :NoteCollectionGuid"); $pdo->bindValue(":NoteTakerGuid", $noteTakerGuid); $pdo->bindValue(":NoteCollectionGuid", $noteCollectionGuid); $pdo->execute(); $rows = $pdo->fetchAll(PDO::FETCH_ASSOC); if (count($rows) == 1) { return $rows[0]["Id"]; } return false; }
function Update($table, $arr) { $db = GetDatabaseConnection(); $params = PrepareGenericArray($arr); $excludedArray = array(); $excludedArray[] = "Id"; $stmt = $db->prepare('UPDATE ' . $table . ' SET ' . ConstructMiddleSQL("update", $params, $excludedArray) . ' WHERE Id = :Id'); return $stmt->execute($params); }
private function countExistingBeers(Drinker $drinker) { $db = GetDatabaseConnection(); $pdo = $db->prepare("SELECT COUNT(*) FROM Beers WHERE DrinkerId=:Id"); $pdo->bindParam(":Id", $drinker->Id); $pdo->execute(); return $pdo->fetch(PDO::FETCH_NUM)[0]; }
private function getUniqueGuid($guid) { $db = GetDatabaseConnection(); $pdo = $db->prepare("SELECT * FROM Notes WHERE UserGuid LIKE :Id GROUP BY UserGuid"); $pdo->bindValue(":Id", $guid . "%"); $pdo->execute(); $arr = $pdo->fetchAll(PDO::FETCH_ASSOC); if (count($arr) == 1) { return $arr[0]["UserGuid"]; } return false; }
/** * @param $noteTakerGuid * @param NoteCollection[] $collections */ private function addNoteCollections($noteTakerGuid, array $collections) { $ret = true; $noteTakerId = $this->getNoteTakerId($noteTakerGuid); foreach ($collections as $collection) { if (Insert("NoteCollections", $collection)) { $db = GetDatabaseConnection(); $pdo = $db->prepare("INSERT INTO NoteTakerNoteCollectionRelations (NoteTakerId, NoteCollectionId)\n VALUES (:NoteTakerId, :NoteCollectionId)"); $pdo->bindValue(":NoteTakerId", $noteTakerId); $pdo->bindValue(":NoteCollectionId", $collection->Id); $ret &= $pdo->execute(); } else { $ret = false; } } return $ret; }
function transactionSupplier($iid, $buyer) { //query creation //Use "LIKE" because then we can pattern match. $supplierQuery = "SELECT * FROM supplier_stocked NATURAL JOIN item I NATURAL JOIN sale_item WHERE I.iid = '" . $iid . "';"; //query database $databaseConnection = GetDatabaseConnection(); $supplierResult = $databaseConnection->query($supplierQuery); //Loop through the results and add each row to an array. $output = array(); while ($row = $supplierResult->fetch_assoc()) { array_push($output, $row); } $supplierQuery = "SELECT * FROM supplier_stocked NATURAL JOIN item I NATURAL JOIN auction_item WHERE I.iid = '" . $iid . "';"; //query database $databaseConnection = GetDatabaseConnection(); $supplierResult = $databaseConnection->query($supplierQuery); //Loop through the results and add each row to an array. while ($row = $supplierResult->fetch_assoc()) { array_push($output, $row); } if (count($output) == 0) { return json_encode(array("error" => "item id not found")); } $item = $output[0]; $itemName = $item["name"]; $seller = $item["supplier"]; if (isset($item["min_price"])) { $price = $item["min_price"]; $buyerEmail = getEmailFromUser($buyer); mail($buyerEmail, "[maetS] Auction won - {$itemName}", "contact {$sellerEmail}"); } else { $price = $item["price"]; $buyerEmail = getEmailFromUser($buyer); mail($buyerEmail, "[maetS] Item Purchased - {$itemName}", "Payment has been processed. Your item will be shipping shortly."); } $transQuery = sprintf("INSERT INTO supplier_Trans (`supplier`,`username`, `iid`,`stdate`) VALUES ('%s','%s','%s',now())", $seller, $buyer, $iid); $transResult = $databaseConnection->query($transQuery); if ($transResult == false) { return json_encode(array("error" => $databaseConnection->error)); } $userQuery = "DELETE FROM supplier_stocked WHERE iid='" . $iid . "'"; $userResult = $databaseConnection->query($userQuery); if ($userResult == false) { return json_encode(array("error" => $databaseConnection->error)); } return json_encode(array("success" => true)); }