Advertisement
jokoui

DBGame.php

Nov 23rd, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.84 KB | None | 0 0
  1. <?php
  2.  
  3. class DBGame {
  4.  
  5.     private $username = "root";
  6.     private $password = "";
  7.     private $db = "rev_game";
  8.     private $host = "localhost";
  9.     private $mysqli;
  10.     public $con;
  11.  
  12.     public function connect() {
  13.         $this->mysqli = new mysqli($this->host, $this->username, $this->password, $this->db);
  14.     }
  15.  
  16.     public function close() {
  17.         mysqli_close($this->mysqli);
  18.     }
  19.  
  20.     public function createGame($nama, $category, $sinopsis, $cpu, $ram, $os, $gpu) {
  21.         $this->mysqli->query("INSERT INTO game (nama, category, sinopsis) VALUES ('$nama', '$category', '$sinopsis')");
  22.         $this->mysqli->query("INSERT INTO spec (CPU, RAM, OS, GPU, idGame) SELECT '$cpu','$ram','$os', '$gpu', game.idGame FROM game WHERE game.nama = '$nama' ");
  23.         $idGuame = $this->mysqli->query("SELECT * FROM game WHERE nama = '$nama'");
  24.         return $idGuame;
  25.         // $this->mysqli->query("INSERT INTO preview (directory, idGame) SELECT '$trailer', game.idGame FROM game WHERE game.nama = '$nama' ");
  26.         // $this->mysqli->query("INSERT INTO preview (directory, idGame) SELECT '$ss', game.idGame FROM game WHERE game.nama = '$nama' ");
  27.     }
  28.  
  29.     public function createPrevHead($idGame, $trailer, $ss, $head) {
  30.         $this->mysqli->query("INSERT INTO preview (directory, idGame, type) VALUES ('$trailer', '$idGame', 1)");
  31.         $this->mysqli->query("INSERT INTO preview (directory, idGame, type) VALUES ('$ss', '$idGame', 0)");
  32.         $this->mysqli->query("INSERT INTO header (directory, idGame) VALUES ('$head', '$idGame')");
  33.     }
  34.  
  35.     public function fetchData($idGame) {
  36.         $dataGame = $this->mysqli->query("select * from `game` where game.idGame = $idGame");
  37.         return $dataGame;
  38.     }
  39.  
  40.     public function fetchDataHeader($idGame) {
  41.         $dataGame = $this->mysqli->query("select * from game join header on game.idGame = header.idGame where game.idGame = $idGame");
  42.         return $dataGame;
  43.     }
  44.  
  45.     public function fetchDataSpec($idGame) {
  46.         $dataSpec = $this->mysqli->query("select * from spec where spec.idGame = $idGame");
  47.         return $dataSpec;
  48.     }
  49.  
  50.     public function fetchDataSlider($idGame) {
  51.         $dataSlider = $this->mysqli->query("SELECT * FROM preview WHERE preview.idGame = $idGame AND preview.type = 0");
  52.         return $dataSlider;
  53.     }
  54.  
  55.     public function fetchDataVideo($idGame) {
  56.         $dataVideo = $this->mysqli->query("SELECT * FROM preview WHERE preview.idGame = $idGame AND preview.type = 1");
  57.         return $dataVideo;
  58.     }
  59.  
  60.     public function fetchDataSearch($sCari, $kategori) {
  61.         $dataSearch = $this->mysqli->query("select * from game where nama=$sCari and category=$kategori");
  62.         return $dataSearch;
  63.     }
  64.  
  65.     public function cekRev($idMember, $idGame) {
  66.         $dataCek = $this->mysqli->query("select count(*) from review where idGame='$idGame' and idMember = '$idMember'");
  67.         return $dataCek;
  68.     }
  69.  
  70.     public function saveReview($idMember, $idGame, $isi) {
  71.         $this->mysqli->query("insert into review (isi, idMember, idGame) values ('$isi','$idMember','$idGame')");
  72.     }
  73.  
  74.     public function fetchNewAdd() {
  75.         $dataNew = $this->mysqli->query("SELECT * FROM game join header on game.idGame= header.idGame order BY game.idGame DESC Limit 5");
  76.         return $dataNew;
  77.     }
  78.  
  79.     public function fetchHot() {
  80.         $dataHot = $this->mysqli->query("select * from game join header on game.idGame=header.idGame order by view desc limit 5");
  81.         return $dataHot;
  82.     }
  83.  
  84.     public function fetchTopEach() {
  85.         $data = $this->mysqli->query("SELECT *, MAX(rating) FROM game join header on game.idGame=header.idGame GROUP BY `category`");
  86.         return $data;
  87.     }
  88.  
  89.     public function fetchTopRated() {
  90.         $dataTop = $this->mysqli->query("select * from game join header on game.idGame=header.idGame order by rating desc limit 3");
  91.         return $dataTop;
  92.     }
  93.  
  94.     public function fetchNewRev() {
  95.         $dataNewRev = $this->mysqli->query("SELECT * from member join review on member.idMember=review.idMember JOIN game on review.idGame=game.idGame ORDER BY idReview DESC LIMIT 5");
  96.         return $dataNewRev;
  97.     }
  98.  
  99.     public function getAllGames() {
  100.         $dataNewRev = $this->mysqli->query("select * from game join header on game.idGame=header.idGame");
  101.         return $dataNewRev;
  102.     }
  103.  
  104.     public function getCatGames($kategori) {
  105.         $dataNewRev = $this->mysqli->query("select * from game join header on game.idGame=header.idGame where category='$kategori'");
  106.         return $dataNewRev;
  107.     }
  108.  
  109.     public function getTheGame($string, $kategori) {
  110.         // $dataNewRev = $this->mysqli->query("select * from game join header on game.idGame=header.idGame where category='$kategori' and nama='$string'");
  111.         $dataNewRev = $this->mysqli->query("SELECT * FROM game JOIN header ON game.idGame=header.idGame WHERE category='$kategori' AND LOCATE('$string', nama) NOT LIKE 0");
  112.         return $dataNewRev;
  113.     }
  114.  
  115.     public function getGame($string, $kategori) {
  116.         $dataGame = $this->mysqli->query("SELECT * FROM game JOIN header ON game.idGame=header.idGame WHERE locate('$string', nama) NOT LIKE 0");
  117.         return $dataGame;
  118.     }
  119.  
  120.     //Mas ali
  121.     function execute($query) {
  122.         $con = mysqli_connect("localhost", "root", "", "rev_game");
  123.         return mysqli_query($con, $query);
  124.     }
  125.  
  126.     function updateRating($hasil, $idGame, $dataMemberBaru, $hasilRating) {
  127.         $query = "update game set rating='$hasilRating', MemberMerating='$dataMemberBaru', totalRating='$hasil' where idGame='$idGame'";
  128.         return $this->execute($query);
  129.     }
  130.  
  131.     function lihatGame($idGame) {
  132.         $query = "select * from game where idGame='$idGame'";
  133.         return $this->execute($query);
  134.     }
  135.  
  136.     function fetch($var) {
  137.         return mysqli_fetch_array($var);
  138.     }
  139.  
  140.     function fetchDataReview($idGame) {
  141.         $data = $this->mysqli->query("SELECT * FROM `review` JOIN member on review.idMember=member.idMember WHERE review.idGame = $idGame");
  142.         return $data;
  143.     }
  144.  
  145.     public function deleteGame($idGame) {
  146.         $query = "delete from game where idGame='$idGame'";
  147.         $query2 = "delete from header where idGame='$idGame'";
  148.         $query3 = "delete from preview where idGame='$idGame'";
  149.         $query4 = "delete from review where idGame='$idGame'";
  150.         $query5 = "delete from spec where idGame='$idGame'";
  151.         $this->mysqli->query($query);
  152.         $this->mysqli->query($query2);
  153.         $this->mysqli->query($query3);
  154.         $this->mysqli->query($query4);
  155.         $this->mysqli->query($query5);
  156.     }
  157.  
  158.     public function insertReview($eReview, $idGame, $idMember) {
  159.         $idMem = $idGame;
  160.         $idG = $idMember;
  161.         $this->mysqli->query("UPDATE `review` SET isi ='$eReview' WHERE `idMember` ='$idMem' and `idGame` ='$idG'");
  162.     }
  163.  
  164. }
  165.  
  166. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement