Guest User

Untitled

a guest
Mar 5th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.91 KB | None | 0 0
  1. <?php
  2. class DBController {
  3.     private $host = "localhost";
  4.     private $user = "root";
  5.     private $password = "root";
  6.     private $database = "ebaylike";
  7.    
  8.     private $conn;
  9.    
  10.     function __construct() {
  11.         $this->conn = $this->connectDB();
  12.         if(!empty($this->conn)) {
  13.             $this->selectDB();
  14.         }
  15.     }
  16.    
  17.     function connectDB() {
  18.         $conn = mysqli_connect($this->host,$this->user,$this->password,$this->database);
  19.         return $conn;
  20.     }
  21.    
  22.     function selectDB() {
  23.         mysqli_select_db($this->conn, $this->database);
  24.     }
  25.    
  26.     function runQuery($query) {
  27.         $result = mysqli_query($this->conn, $query);
  28.         while($row=mysqli_fetch_assoc($result)) {
  29.             $resultset[] = $row;
  30.         }
  31.         if(!empty($resultset))
  32.             return $resultset;
  33.     }
  34.    
  35.     function numRows($query) {
  36.         $result  = mysqli_query($this->conn, $query);
  37.         $rowcount = mysqli_num_rows($result);
  38.         return $rowcount;
  39.     }
  40. }
  41. ?>
Add Comment
Please, Sign In to add comment