Advertisement
Guest User

Corrected SO class

a guest
Jan 28th, 2014
2,331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.72 KB | None | 0 0
  1.    
  2.  
  3.     <?php
  4.      
  5.     namespace Revolution;
  6.     if(!defined('IN_INDEX')) { die('Sorry, you cannot access this file.'); }
  7.     class engine
  8.     {
  9.             private $initiated;
  10.             private $connected;
  11.            
  12.             private $connection;
  13.            
  14.             final public function Initiate()
  15.             {
  16.                     global $_CONFIG;
  17.                     if(!$this->initiated)
  18.                     {
  19.                             $this->setMySQL('connect', mysql_connect);
  20.                             $this->setMySQL('pconnect', mysql_pconnect);
  21.                             $this->setMysql('select_db', mysql_select_db);
  22.                             $this->setMySQL('query', mysql_query);
  23.                             $this->setMySQL('num_rows', mysql_num_rows);
  24.                             $this->setMySQL('fetch_assoc', mysql_fetch_assoc);
  25.                             $this->setMySQL('fetch_array',mysql_fetch_array);
  26.                             $this->setMySQL('result', mysql_result);
  27.                             $this->setMySQL('free_result', mysql_free_result);
  28.                             $this->setMySQL('escape_string', mysql_real_escape_string);
  29.                            
  30.                             $this->initiated = true;
  31.                    
  32.                             $this->connect($_CONFIG['mysql']['connection_type']);
  33.                     }
  34.             }
  35.            
  36.             final public function setMySQL($key, $value)
  37.             {
  38.                     $this->mysql[$key] = $value;
  39.             }
  40.            
  41.            
  42.             /*-------------------------------Manage Connection-------------------------------------*/
  43.            
  44.             final public function connect($type)
  45.             {
  46.                     global $core, $_CONFIG;
  47.                     if(!$this->connected)
  48.                     {
  49.                             $_CONFIG['hostname'] = 'localhost';
  50.                             $_CONFIG['username'] = 'root';
  51.                             $_CONFIG['password'] = '***';
  52.      
  53.                             if (!isset($this->mysql[$type])) {
  54.                                 throw new \Exception("MySQL $type is not defined.");
  55.                             } /* MISSING CLOSING BRACKET HERE */
  56.                            
  57.                             if($this->connection)
  58.                             {
  59.                                     $mydatabase = $this->mysql['select_db']($_CONFIG['mysql']['database'], $this->connection);
  60.                                    
  61.                                     if($mydatabase)
  62.                                     {
  63.                                             $this->connected = true;      
  64.                                     }
  65.                                     else
  66.                                     {
  67.                                             $core->systemError('MySQL Engine', 'MySQL could not connect to database');
  68.                                     }
  69.                             }
  70.                             else
  71.                             {
  72.                                     $core->systemError('MySQL Engine', '<b>Remote Server:</b> The remote server seems to be offline, odd, it\'s being looked into.');                      
  73.                                     //$core->systemError('MySQL Engine', 'MySQL could not connect to host');                      
  74.                             }
  75.                     }
  76.             }
  77.            
  78.             final public function disconnect()
  79.             {
  80.                     global $core;
  81.                     if($this->connected)
  82.                     {
  83.                             if($this->mysql['close'])
  84.                             {
  85.                                     $this->connected = false;
  86.                             }
  87.                             else
  88.                             {
  89.                                     $core->systemError('MySQL Engine', 'MySQL could not disconnect.');
  90.                             }
  91.                     }
  92.             }
  93.            
  94.             /*-------------------------------Secure MySQL variables-------------------------------------*/
  95.            
  96.             final public function secure($var)
  97.             {
  98.                     return $this->mysql['escape_string'](stripslashes(htmlspecialchars($var)));
  99.             }
  100.            
  101.             /*-------------------------------Manage MySQL queries-------------------------------------*/
  102.            
  103.             final public function query($sql)
  104.             {
  105.                     return $this->mysql['query']($sql, $this->connection) or die(mysql_error());
  106.             }
  107.            
  108.             final public function num_rows($sql)
  109.             {
  110.                     return $this->mysql['num_rows']($this->mysql['query']($sql, $this->connection));
  111.             }
  112.            
  113.             final public function result($sql)
  114.             {
  115.                     return $this->mysql['result']($this->mysql['query']($sql, $this->connection), 0);
  116.             }
  117.            
  118.             final public function free_result($sql)
  119.             {
  120.                     return $this->mysql['free_result']($sql);
  121.             }
  122.            
  123.             final public function fetch_array($sql)
  124.             {
  125.                     $query = $this->mysql['query']($sql, $this->connection);
  126.                    
  127.                     $data = array();
  128.                    
  129.                     while($row = $this->mysql['fetch_array']($query))
  130.                     {
  131.                             $data[] = $row;
  132.                     }
  133.                    
  134.                     return $data;
  135.             }
  136.            
  137.             final public function fetch_assoc($sql)
  138.             {
  139.                     return $this->mysql['fetch_assoc']($this->mysql['query']($sql, $this->connection));
  140.             }
  141.     }
  142.     ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement