Advertisement
Guest User

Untitled

a guest
Aug 14th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.89 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Description of class
  5.  *
  6.  * @author manuelfernandez
  7.  */
  8.  
  9. namespace ManuelFernandez;
  10.  
  11. class engine
  12. {
  13.  
  14.    private $hostname;
  15.    private $username;
  16.    private $password;
  17.    private $database;
  18.  
  19.    private $connection;
  20.    private $selection;
  21.  
  22.    private $functions = array(
  23.     'connect'                   =>          'mysql_connect',
  24.     'select_db'                 =>          'mysql_select_db',
  25.     'query'                     =>          'mysql_query',
  26.     'free_result'                                   =>          'mysql_free_result',
  27.     'result'                    =>          'mysql_result',
  28.     'num_rows'                  =>          'mysql_num_rows',
  29.     'fetch_array'                                   =>          'mysql_fetch_array',
  30.         'fetch_assoc'                                   =>                      'mysql_fetch_assoc'
  31.     );
  32.  
  33.    private $fetchtypes = array(
  34.         'assoc'                                         =>                      'MYSQL_ASSOC',
  35.         'both'                                          =>                      'MYSQL_BOTH'
  36.    );
  37.  
  38.    final public function MFconfigurate()
  39.     {
  40.         global $core;
  41.  
  42.         if(file_exists('app/config.php'))
  43.         {
  44.              include('app/config.php');
  45.              $this->hostname = $CONFIG['mysql_hostname'];
  46.              $this->username = $CONFIG['mysql_username'];
  47.              $this->password = $CONFIG['mysql_password'];
  48.              $this->database = $CONFIG['mysql_database'];
  49.         }
  50.         else
  51.         {
  52.            $core->MFerror('config');
  53.         }
  54.     }
  55.    
  56.    final public function connect()
  57.    {
  58.        global $core;
  59.        $this->connection = $this->functions['connect']($this->hostname, $this->username, $this->password) or die(mysql_error());
  60.        $this->selection = $this->functions['select_db']($this->database) or die(mysql_error());
  61.  
  62.        if(is_resource($this->connection) && $this->selection == true)
  63.        {
  64.            $this->connection = true;
  65.            $this->selection = true;
  66.        }
  67.        else
  68.        {
  69.            $core->MFerror('mysql');
  70.        }
  71.  
  72.    }
  73.  
  74.    final public function secure($str)
  75.    {
  76.        return mysql_real_escape_string(strip_tags(htmlspecialchars($str)));
  77.    }
  78.    
  79.    final public function executeQuery($sql)
  80.    {
  81.        return $this->functions['query']($sql);
  82.    }
  83.  
  84.    final public function fetch_array($sql, $fetchtype)
  85.    {
  86.        return $this->functions['fetch_array']($this->functions['query']($sql, $this->fetchtypes[$fetchtype]));
  87.    }
  88.  
  89.    final public function fetch_assoc($sql)
  90.    {
  91.        return $this->functions['fetch_assoc']($this->functions['query']($sql));
  92.    }
  93.  
  94.    final public function num_rows($sql)
  95.    {
  96.        return $this->functions['num_rows']($sql);
  97.    }
  98.  
  99.    final public function result($sql, $int)
  100.    {
  101.        return $this->functions['result']($this->functions['query']($sql), $int);
  102.    }
  103.  
  104.    final public function free_result($sql)
  105.    {
  106.        return $this->functions['free_result']($sql);
  107.    }
  108.  
  109. }
  110.  
  111. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement