-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.php
More file actions
46 lines (35 loc) · 1.25 KB
/
test.php
File metadata and controls
46 lines (35 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
const SERVERNAME = "localhost";
const USERNAME = "root";
const PASSWORD = "t3cht0n!c";
const DB = "myDatabase";
function getCard($player)
{
$conn = new mysqli(SERVERNAME, USERNAME, PASSWORD, DB);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM Cards WHERE InPlay = 0";
$result = $conn->query($sql);
$cardData = $result->fetch_assoc();
$max = count($cardData) -1;
$random = mt_rand(0, $max);
$id = $cardData[$random]["idCards"];
$updateSql = 'UPDATE Cards SET InPlay = 1 WHERE idCards = ' . $id;
if($conn->query($updateSql) === FALSE){
echo "error updating: " . $conn->error;
}
$card = new Card($cardData["Suit"], $cardData["CardValue"], $cardData["ImageLocation"]);
$addToHand = "INSERT INTO Hands (CardId, HandOwner) VALUES ('$id', '$player')";
if($conn->query($addToHand) === FALSE){
echo "error adding to hand: " . $conn->error;
}
if(!$conn->commit())
{
echo "commit failed";
}
$conn->close();
return $card;
}
getCard("player");
?>