Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define("DB_USER","");
- define("DB_PASS","");
- define("DB_HOST","");
- define("DB_BASE","");
- class database {
- function conn(){
- $conn = mysqli_connect(DB_HOST,DB_USER,DB_PASS,DB_BASE) or die("The database got shit on mate.");
- return $conn;
- }
- function query($conn,$passcode,$username,$result){
- $que = "INSERT INTO results (username,passcode,date,result) VALUES ('".$username."','".$passcode."','".date('m-d-Y')."','".$result."')";
- if($stmt = mysqli_prepare($conn,$que)) {
- mysqli_stmt_execute($stmt);
- mysqli_stmt_close($stmt);
- }
- mysqli_close($conn);
- return True;
- }
- function gather($conn,$passcode){
- $query = "SELECT username,result FROM results WHERE passcode='".$passcode."'";
- if($stmt = mysqli_prepare($conn,$query)) {
- mysqli_stmt_execute($stmt);
- mysqli_stmt_bind_result($stmt,$name,$res);
- $cho = array();
- $nam = array();
- while(mysqli_stmt_fetch($stmt)) {
- $cho[] = $res;
- $nam[] = $name;
- }
- if(count($cho) < 2) {
- return '<center><span style="color:rgb(120,0,0);">No Cheating Please!</span></center><br><br>';
- } elseif(count($cho) > 2) {
- return '<center><span style="color:rgb(0,0,120);">This is a 2 player game for now!</span></center><br><br>';
- } else {
- if((int)$cho[0] == (int)$cho[1]) {
- return '<center><span style="color:rgb(120,120,120);">TIE!</span></center><br><br>';
- } elseif(((int)$cho[0] == 1) && ((int)$cho[1] == 2)) {
- return '<center><span style="color:rgb(0,120,0);">'.$nam[1].' WINS!</span></center><br><br>';
- } elseif(((int)$cho[0] == 1) && ((int)$cho[1] == 3)) {
- return '<center><span style="color:rgb(0,120,0);">'.$nam[0].' WINS!</span></center><br><br>';
- } elseif(((int)$cho[0] == 2) && ((int)$cho[1] == 1)) {
- return '<center><span style="color:rgb(0,120,0);">'.$nam[0].' WINS!</span></center><br><br>';
- } elseif(((int)$cho[0] == 2) && ((int)$cho[1] == 3)) {
- return '<center><span style="color:rgb(0,120,0);">'.$nam[1].' WINS!</span></center><br><br>';
- } elseif(((int)$cho[0] == 3) && ((int)$cho[1] == 1)) {
- return '<center><span style="color:rgb(0,120,0);">'.$nam[1].' WINS!</span></center><br><br>';
- } elseif(((int)$cho[0] == 3) && ((int)$cho[1] == 2)) {
- return '<center><span style="color:rgb(0,120,0);">'.$nam[0].' WINS!</span></center><br><br>';
- } else {
- return False;
- }
- }
- mysqli_stmt_close($stmt);
- }
- mysqli_close($conn);
- return True;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement