Guest User

dbcontroller.php

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