Advertisement
MRYDesign

Bas - DB Object - Part 2

Oct 3rd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.48 KB | None | 0 0
  1. <?php
  2.  
  3. class MRY_DatabaseWrapper extends database {
  4.    
  5.     public $_columns = array ();
  6.     public $_values = array ();
  7.     public $_where = array ();
  8.     public $_table = array ();
  9.     public $_joinTable = array ();
  10.     public $_type = 'select';
  11.     public $query;
  12.    
  13.     public function column ($column) {
  14.         $this->_columns[] = $column;
  15.         return $this;
  16.     }
  17.    
  18.     public function table ($table) {
  19.         $this->_table[] = $table;
  20.         return $this;
  21.     }
  22.    
  23.     public function values ($values) {
  24.         $this->_values[] = $values;
  25.         return $this;
  26.     }
  27.    
  28.     public function where ($column, $type, $value) {
  29.         $this->_where[] = $column . ' ' . $type . ' ' . $value;
  30.         return $this;
  31.     }
  32.    
  33.     public function type ($type) {
  34.         $this->_type = $type;
  35.         return $this;
  36.     }
  37.    
  38.     public function joinTable ($type, $table) {
  39.         $this->_joinTable[] = $type . ' ' . $table;
  40.         return $this;
  41.     }
  42.    
  43.     public function fetch () {
  44.         $data = $this->_query ();
  45.         return $data;
  46.     }
  47.    
  48.     public function _query () {
  49.        
  50.         switch ($this->_type) {
  51.            
  52.             case 'select':
  53.                
  54.                 $query = 'SELECT ';
  55.                 $query .= implode (',', $this->_columns);
  56.                 $query .= ' FROM ' . current ($this->_table);
  57.                
  58.                 $where = array ();
  59.                
  60.                 if (!empty ($this->_where)) {
  61.                    
  62.                     $query .= ' WHERE ' . implode (' AND ', $this->_where);
  63.                 }
  64.                
  65.                 parent::query ($query);
  66.                 $data = parent::fetch ();
  67.                
  68.                 break;
  69.         }
  70.         var_dump ($query, $data);
  71.        
  72.         return $data;
  73.        
  74.     }
  75.    
  76.     public function _get () {
  77.         //var_dump ($this);
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement