Guest User

Untitled

a guest
Nov 16th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.23 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. error_reporting(E_ALL);
  5.  
  6.  
  7. class MySQL
  8. {
  9.     private static $connection = NULL;
  10.    
  11.     var $hostname = 'localhost';
  12.     var $username = 'root';
  13.     var $password = '';
  14.     var $database = 'db_source';
  15.     var $table = 'tbl_source';
  16.    
  17.     var $error_message = '';
  18.    
  19.     protected $is_ready = false;
  20.    
  21.    
  22.    
  23.     function __construct()
  24.     {
  25.         if( !$this->connect() || !$this->select_db() )
  26.         {
  27.             $this->set_error(__FUNCTION__);
  28.             return;
  29.         }
  30.        
  31.         $this->is_ready = true;
  32.     }
  33.    
  34.    
  35.    
  36.     function set_error($message)
  37.     {
  38.         $this->error_message = $message;
  39.         return false;
  40.     }
  41.    
  42.    
  43.    
  44.     function is_ready()
  45.     {
  46.         return $this->is_ready;
  47.     }
  48.    
  49.    
  50.    
  51.     function connect()
  52.     {
  53.         self::$connection = mysql_connect(
  54.             empty($this->hostname) ? 'localhost' : $this->hostname,
  55.             empty($this->username) ? 'root' : $this->username,
  56.             empty($this->password) ? '' : $this->password
  57.         );
  58.        
  59.         return $this->is_connected() ? true : $this->set_error(__FUNCTION__);
  60.     }
  61.    
  62.    
  63.    
  64.     function select_db()
  65.     {
  66.         if( !$this->is_connected() )
  67.             return $this->set_error(__FUNCTION__);
  68.        
  69.         return mysql_select_db($this->database, self::connection);
  70.     }
  71.    
  72.    
  73.    
  74.     function is_connected()
  75.     {
  76.         return is_resource(self::connection) ? true : false;
  77.     }
  78.    
  79. }
  80.  
  81. ?>
Add Comment
Please, Sign In to add comment