Advertisement
Guest User

class

a guest
Oct 6th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.80 KB | None | 0 0
  1. class DbDriver {
  2.   private $host;
  3.   private $user;
  4.   private $password;
  5.   private $database;
  6.   private $last_query;
  7.   private $handle;
  8.  
  9.   function __construct($host,$user,$password,$database){
  10.     $this->host = $host;
  11.     $this->user = $user;
  12.     $this->password = $password;
  13.     $this->database = $database;
  14.     $this->connect();
  15.   }
  16.  
  17.   private function connect() {
  18.     $this->handle = @new mysqli($this->host,$this->user,$this->password,$this->database);
  19.     $this->handle->query("SET NAMES 'utf8' ");
  20.  
  21.     if ($this->handle->connect_errno){
  22.       echo "Błąd połączenia z bazą";
  23.     }
  24.   }
  25.  
  26.   function getSalon($id){
  27.     $query = "SELECT * FROM `adminpanel_salon` WHERE `id`='{$id}' ";
  28.     $this->last_query = $this->handle->query($query);
  29.  
  30.  
  31.       while ($row = $this->last_query->fetch_object()) {
  32.         $data = array(
  33.           "id" => $row->id,
  34.           "name" => $row->name
  35.         );
  36.       }
  37.  
  38.     return $data['name'];
  39.   }
  40.  function getUsersDataAsTable($access){
  41.     $query = "SELECT * FROM `adminpanel_users` WHERE `access`='{$access}'";
  42.     $this->last_query = $this->handle->query($query);
  43.  
  44.  
  45.     ?>
  46.       <table class="table">
  47.         <thead>
  48.           <tr>
  49.             <th>#</th>
  50.             <th>User</th>
  51.             <th>Uprawnienia</th>
  52.             <th>Pracownik</th>
  53.             <th>Salon</th>
  54.  
  55.           </tr>
  56.         </thead>
  57.         <tbody>
  58.       <?php
  59.  
  60.       while ($row = $this->last_query->fetch_object()) {
  61.         echo "<tr>";
  62.         echo '<td>'. $row->id.'</td>';
  63.         echo '<td>'. $row->user.'</td>';
  64.         echo '<td>'. $row->access.'</td>';
  65.         echo '<td>'. $row->parent.'</td>';
  66.         echo '<td>'. $this->getSalon($row->salon).'</td>';
  67.  
  68.         echo "</tr>";
  69.       }
  70.       ?>
  71.         </tbody>
  72.       </table>
  73.   <?php
  74.  
  75.   }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement