You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.2 KiB
PHP

<?php
function getRecord($pdo, $from, $where ){
$conn = $pdo;
try {
$sql = "SELECT * FROM $from WHERE id = $where";
$stmt = $conn->prepare($sql);
$stmt->execute();
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
$record = $stmt->fetch();
} catch (PDOException $e) {
echo "Error in $from: Not Found";
}
return $record;
}
function isThisBound($pdo, $where, $item_id, $user_id){
$conn = $pdo;
try {
if($where === "list"){
$item = "beer_id";
}else $item = "brewery_id";
$sql = "SELECT * FROM $where WHERE $item=$item_id AND user_id=$user_id";
$stmt = $conn->prepare($sql);
$stmt->execute();
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
if($stmt->rowCount() == 1)return true;
else return false;
} catch (PDOException $e) {
echo "Error in $where: Not Found";
}
}
function getRating($pdo, $beer, $user){
$conn = $pdo;
try {
$sql = "SELECT * FROM list WHERE beer_id = $beer AND user_id = $user";
$stmt = $conn->prepare($sql);
$stmt->execute();
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
$rating = $stmt->fetch();
} catch (PDOException $e) {
echo "Error in $from: Not Found";
}
return $rating;
}