Advertisement
Guest User

Untitled

a guest
Mar 16th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.71 KB | None | 0 0
  1. Line 64 - parent::read('app_users', null, null, "WHERE {$this->places}", null, $this->parses);
  2.  
  3. Read.php
  4.  
  5. <?php
  6. namespace app\Controllers\Dns
  7. {
  8.     use PDO;
  9.  
  10.     class Read extends Conn
  11.     {
  12.         private $select;
  13.         private $places;
  14.         private $callback;
  15.  
  16.         /** @var PDOStatement */
  17.         private $read;
  18.  
  19.         public function read($table, $fields = '*', $inners = null, $clause = null, $others_clause = null, $parse = null)
  20.         {
  21.             $this->parses($parse);
  22.             $this->select = "SELECT {$fields} FROM {$table} {$inners} {$clause} {$others_clause}";
  23.             $this->execute();
  24.         }
  25.        
  26.         public function result()
  27.         {
  28.             return $this->result;
  29.         }
  30.  
  31.         public function rowcount()
  32.         {
  33.             return $this->Read->rowCount();
  34.         }
  35.        
  36.         public function columnName($columnName)
  37.         {
  38.             if($this->rowcount > 0):
  39.                 foreach($this->result as $this->callback):
  40.                     return $this->callback->$columnName;               
  41.                 endforeach;        
  42.             endif;
  43.         }
  44.  
  45.         private function parses($parse)
  46.         {
  47.             if(!empty($parse)):
  48.                 $this->places = $parse;
  49.                 parse_str($parse,  $this->places);
  50.             endif;
  51.         }
  52.          
  53.         private function connect()
  54.         {
  55.             $this->Read = parent::conn()->prepare($this->select);
  56.             $this->Read->setFetchMode(PDO::FETCH_OBJ);
  57.         }
  58.  
  59.         private function syntax()
  60.         {
  61.             if($this->places):
  62.                 foreach($this->places as $index => $value):
  63.                     if($index == 'limit' || $index == 'offset'):
  64.                         $value = (int) $value;
  65.                     endif;
  66.                     $this->Read->bindValue(":{$index}", $value, (is_int($value) ? PDO::PARAM_INT : PDO::PARAM_STR));
  67.                 endforeach;
  68.             endif;
  69.         }
  70.  
  71.         protected function Execute() {
  72.             $this->connect();
  73.             try{
  74.                 $this->syntax();
  75.                 $this->Read->execute();
  76.                 $this->Result = $this->Read->fetchAll();
  77.             } catch (PDOException $e) {
  78.                 // Manager errors here
  79.             }
  80.         }
  81.     }
  82.  
  83. }
  84.  
  85.  
  86. Conn.php
  87. <?php
  88. namespace app\Controllers\Dns
  89. {
  90.     use PDO;
  91.    
  92.     /**
  93.      * Class Conn
  94.      * @package app\Controller
  95.      */
  96.     class Conn
  97.     {
  98.         /** @var string */
  99.         private $mysql_host = 'localhost';
  100.  
  101.         /** @var string */
  102.         private $mysql_user = 'root';
  103.  
  104.         /** @var string */
  105.         private $mysql_password = '';
  106.  
  107.         /** @var string */
  108.         private $mysql_database = 'user';
  109.  
  110.         /** @var null */
  111.         private $connect = null;
  112.  
  113.         /** @ar array */
  114.         private $options;
  115.  
  116.         /** @var string */
  117.         private $dns;
  118.  
  119.         private function connect()
  120.         {
  121.             try {
  122. line 36 -       if(!$this->connect):
  123.                     $this->options = [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8'];
  124.                     $this->dns = 'mysql:host=' . $this->mysql_host . ';dbname=' . $this->mysql_database;
  125.                     $this->connect = new PDO($this->dns, $this->mysql_user, $this->mysql_password, $this->options);
  126.                 endif;
  127.             }catch (\PDOException $e){
  128.                 PHPErro($e->getCode(), $e->getMessage(), $e->getFile(), $e->getLine());
  129.                 die();
  130.             }
  131.            
  132.             self::$connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  133.             return self::$connect;
  134.         }
  135.  
  136.         /**
  137.          * @return object
  138.          */
  139.         public static function conn(){
  140.             return self::connect();
  141.         }
  142.     }
  143. }
  144.  
  145. Erro gerado
  146. <b>Fatal error</b>:  Uncaught Error: Using $this when not in object context in Conn.php:36
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement