Advertisement
Guest User

Untitled

a guest
May 26th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.58 KB | None | 0 0
  1. <?php
  2. class DbAction{
  3.   public $query;
  4.   public $result;
  5.   public $connection;
  6.   public $num_rows;
  7.   public $row;
  8.   private $host;
  9.   private $db_user;
  10.   private $db_password;
  11.   private $db_name;
  12.  
  13.   /*
  14.     CONSTRUCTOR
  15.   */
  16.   public function __construct(){
  17.     $this->connection;
  18.     $this->query = '';
  19.     $this->result = '';
  20.     $this->num_rows = '';
  21.     $this->row = '';
  22.     $this->host = "localhost";
  23.     $this->db_user = "root";
  24.     $this->db_password = "";
  25.     $this->db_name = "osadnicy";
  26.   }
  27.  
  28.   /*
  29.     STARTS CONNECTION
  30.   */
  31.   public function connection(){
  32.     $this->connection = new mysqli($this->host, $this->db_user, $this->db_password, $this->db_name );
  33.     if($this->connection == true){
  34.       return true;
  35.     } else {
  36.       $this->errorRaport();
  37.       return false;
  38.     }
  39.   }
  40.  
  41.   /*
  42.     RETURNS RESULT
  43.   */
  44.   public function getResult($query){
  45.     if ($this->result = $this->connection->query($query)) {
  46.       return $this->result;
  47.     } else {
  48.       return false;
  49.     }
  50.   }
  51.  
  52.   /*
  53.     RETURNS NUMBER OF ROW
  54.   */
  55.   public function rowNumber(){
  56.     if($this->numRows =  $this->result->num_rows){
  57.       return $this->numRows;
  58.     } else {
  59.       return false;
  60.     }
  61.   }
  62.  
  63.   /*
  64.     RETURNS ROW
  65.   */
  66.   public function row(){
  67.     if($this->row = $this->result->fetch_assoc()){
  68.       return $this->row;
  69.     } else {
  70.       return false;
  71.     }
  72.   }
  73.  
  74. } // END OF CLASS DbAction
  75.  
  76. $db = new DbAction();
  77. $db->connection();
  78. $db->getResult("SELECT * FROM `uzytkownicy`");
  79. echo $db->rowNumber();
  80. $row = $db->row();
  81. echo $row['user'];
  82. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement