Advertisement
Guest User

Untitled

a guest
Jul 11th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.07 KB | None | 0 0
  1. <?php
  2. class c_mysql {
  3.     private static $_instance = null;
  4.     //connection
  5.     private static $db_host;
  6.     private static $db_name;
  7.     private static $db_user;
  8.     private static $db_pass;
  9.     private $db_conn;
  10.     private $db_bool_result = false;
  11.     //sql
  12.     private $query;
  13.     private $resultquery;
  14.     public $sql;
  15.     private $where;
  16.     private $order;
  17.     public $numrows;
  18.     private $resultarray = array ();
  19.     //errors
  20.     private $error_string;
  21.     private $show_errors;
  22.    
  23.     function __construct() {
  24.         $this->db_host = "****";
  25.         $this->db_name = "****";
  26.         $this->db_user = "****";
  27.         $this->db_pass = "****";
  28.        
  29.         $this->error_string = "";
  30.         $this->show_errors = true;
  31.         $this->connect ();
  32.     }
  33.    
  34.     public static function GetInstance() {
  35.         if (! self::$_instance instanceof self) {
  36.             $x = __CLASS__;
  37.             self::$_instance = new $x ();
  38.        
  39.         }
  40.         return self::$_instance;
  41.     }
  42.    
  43.     public function clear_results_array() {
  44.         $this->resultarray = array ();
  45.    
  46.     }
  47.     public function getInsertId() {
  48.         return @mysql_insert_id ( $this->db_conn );
  49.     }
  50.    
  51.     public function insert($sql) {
  52.         $query = $sql;
  53.        
  54.         $resultquery = @mysql_query ( $query );
  55.        
  56.         return ($resultquery) ? true : false;
  57.    
  58.     }
  59.    
  60.     public function delete($sql, $where) {
  61.         $query = $sql;
  62.         if ($where != "") {
  63.             $query .= ' WHERE ' . $where;
  64.         }
  65.        
  66.         $resultquery = @mysql_query ( $query );
  67.        
  68.         return ($resultquery) ? true : false;
  69.     }
  70.    
  71.     public function update($sql, $where) {
  72.         $query = $sql;
  73.         if ($where != "") {
  74.             $query .= ' WHERE ' . $where;
  75.         }
  76.        
  77.         $resultquery = @mysql_query ( $query );
  78.        
  79.         return ($resultquery) ? true : false;
  80.    
  81.     }
  82.    
  83.     public function select($sql, $where, $groupby, $order, $limit) {
  84.         unset ( $this->resultarray );
  85.         $query = $sql;
  86.         if ($where != "") {
  87.             $query .= ' WHERE ' . $where;
  88.         }
  89.         if ($groupby != "") {
  90.             $query .= ' GROUP BY ' . $groupby;
  91.         }
  92.         if ($order != "") {
  93.             $query .= ' ORDER BY ' . $order;
  94.         }
  95.         if ($limit != "") {
  96.             $query .= ' LIMIT ' . $limit;
  97.         }
  98.         $resultquery = @mysql_query ( $query );
  99.         if ($resultquery) {
  100.             $this->numrows = mysql_num_rows ( $resultquery );
  101.             while ( ($this->resultarray [] = mysql_fetch_assoc ( $resultquery )) || array_pop ( $this->resultarray ) )
  102.                 ;
  103.         }
  104.     }
  105.    
  106.     public function mysql_errors() {
  107.         echo mysql_errno ( $this->db_conn ) . ": " . mysql_error ( $this->db_conn ) . "<br>";
  108.     }
  109.    
  110.     public function connect() {
  111.        
  112.         $this->db_conn = mysql_connect ( $this->db_host, $this->db_user, $this->db_pass );
  113.         if (is_resource ( $this->db_conn )) {
  114.             $this->db_bool_result = @mysql_select_db ( $this->db_name, $this->db_conn );
  115.             if ($this->db_bool_result) {
  116.                 return true;
  117.             } else {
  118.                 if ($this->show_errors) {
  119.                     $this->mysql_errors ();
  120.                 }
  121.                 return false;
  122.             }
  123.         } else {
  124.             if ($this->show_errors) {
  125.                 $this->mysql_errors ();
  126.             }
  127.             return false;
  128.         }
  129.     }
  130.    
  131.     public function get_row_count() {
  132.         return $this->numrows;
  133.     }
  134.    
  135.     public function get_results() {
  136.         return $this->resultarray;
  137.     }
  138.    
  139.     public function close() {
  140.         $this->db_bool_result = mysql_close ( $this->db_conn );
  141.     }
  142.  
  143. }
  144.  
  145. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement