Advertisement
Guest User

Untitled

a guest
Sep 8th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.38 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * $dbase = db::getDB();
  5.  *
  6.  */
  7. class db
  8. {
  9.     public $db_host         = false;
  10.     public $db_name         = false;
  11.     public $db_user         = false;
  12.     public $db_pass         = false;
  13.     protected $dbi          = false;
  14.     private static $instance;
  15.  
  16.     public static function getDB()
  17.     {
  18.         if (!isset(self::$instance))
  19.         {
  20.             self::$instance = new db();
  21.         }
  22.         return self::$instance;
  23.     }
  24.  
  25.     protected function __construct()
  26.     {
  27.         include (__PWC_DIR_CONFIG_MT__ . '/config.php');
  28.         $this->db_host = $dbhost;
  29.         $this->db_name = $dbname;
  30.         $this->db_user = $dbuser;
  31.         $this->db_pass = $dbpass;
  32.         $this->prefix = (empty($prefix) ? 'mt' : $prefix);
  33.     }
  34.  
  35.     private function __clone()
  36.     {
  37.         die ('Bitte die vorhandene Instanz nutzen "$dabse = db::getDB();" / Please use the instance "$dabse = db::getDB();"');
  38.     }
  39.  
  40.     public function sql_connect()
  41.     {
  42.         if (!is_resource($this->dbi))
  43.         {
  44.             $this->dbi = @mysql_connect($this->db_host, $this->db_user, $this->db_pass);
  45.         }
  46.         $this->sql_select_db();
  47.         return $this->dbi;
  48.     }
  49.  
  50.     public function sql_select_db()
  51.     {
  52.         if (!is_resource($this->dbi))
  53.         {
  54.             if (mysql_errno() == 1045)
  55.             {
  56.                 $error_message[] = '(1045) Die Benutzerdaten zur Datenbank sind falsch angegeben!';
  57.             }
  58.             elseif (mysql_errno() == 2005)
  59.             {
  60.                 $error_message[] = '(2005) Der Datenbank-Host ist falsch angegeben!';
  61.             }
  62.             else
  63.             {
  64.                 $error_message[] = mysql_error();
  65.             }
  66.         }
  67.         if (!isset($error_message))
  68.         {
  69.             $isdb = @mysql_select_db($this->db_name, $this->dbi);
  70.             if (!$isdb)
  71.             {
  72.                 if (mysql_errno() == 1049)
  73.                 {
  74.                     $error_message[] = '(1049) Der Datenbank-Name ist falsch angegeben!';
  75.                 }
  76.                 else
  77.                 {
  78.                     $error_message[] = mysql_error();
  79.                 }
  80.             }
  81.         }
  82.         if (isset($error_message))
  83.         {
  84.             arsort($error_message);
  85.             die ('<html><head><title>' . __PWC_NAME__ . ' v' . __PWC_VERSION__ . ' - Datenbank-Fehler</title></head><body text="#000000"><h2>' . __PWC_NAME__ . ' v' . __PWC_VERSION__ . ' - Datenbank-Fehler</h2><b>Sorry, wir haben zur Zeit Probleme mit der Datenbank. (' . mysql_errno() . ')</b><br /><br /><lu><li>' . implode('</li><li>', $error_message) . '<br /><br />' . __POWERED__ . '</body></html>');
  86.         }
  87.         return $this->dbi;
  88.     }
  89.  
  90.     public function sql_logout()
  91.     {
  92.         return true;
  93.     }
  94.  
  95.     public function sql_insert_id()
  96.     {
  97.         return @mysql_insert_id($this->dbi);
  98.     }
  99.  
  100.     public function sql_affected_rows()
  101.     {
  102.         return intval(@mysql_affected_rows($this->dbi));
  103.     }
  104.  
  105.     public function sql_query($query)
  106.     {
  107.         $result = @mysql_query($query, $this->dbi);
  108. //      if (mysql_errno() == 1146)
  109. //      {
  110. //          die ('<html><head><title>' . __PWC_NAME__ . ' v' . __PWC_VERSION__ . ' - Datenbank-Fehler</title></head><body text="#000000"><h2>' . __PWC_NAME__ . ' v' . __PWC_VERSION__ . ' - Datenbank-Fehler</h2><b>Sorry, wir haben zur Zeit Probleme mit der Datenbank.</b><br /><br />' . mysql_errno($this->dbi) . ': ' . mysql_error($this->dbi) . '<br /><br />' . __POWERED__ . '</body></html>');
  111. //      }
  112.         return $result;
  113.     }
  114.  
  115.     public function sql_num_rows($result)
  116.     {
  117.         $rows = intval(@mysql_num_rows($result));
  118.         return $rows;
  119.     }
  120.  
  121.     public function sql_fetch_row($result)
  122.     {
  123.         $row = array();
  124.         $row = @mysql_fetch_row($result);
  125.         return $row;
  126.     }
  127.  
  128.     public function sql_fetch_array($result)
  129.     {
  130.         $row = array();
  131.         $row = @mysql_fetch_array($result);
  132.         return $row;
  133.     }
  134.  
  135.     public function sql_fetch_assoc($result)
  136.     {
  137.         $row = array();
  138.         $row = @mysql_fetch_assoc($result);
  139.         return $row;
  140.     }
  141.  
  142.     public function sql_fetch_object($result)
  143.     {
  144.         $row = @mysql_fetch_object($result);
  145.         return ($row == false) ? false : $row;
  146.     }
  147.  
  148.     public function sql_fetch_rowset($result)
  149.     {
  150.         $rowset = array();
  151.         $row = @mysql_fetch_array($result, MYSQL_ASSOC);
  152.         while ($row)
  153.         {
  154.             $rowset[] = $row;
  155.             $row = @mysql_fetch_array($result, MYSQL_ASSOC);
  156.         }
  157.         return $rowset;
  158.     }
  159.  
  160.     public function sql_free_result($result)
  161.     {
  162.         $row = @mysql_free_result($result);
  163.         return $row;
  164.     }
  165.  
  166.     public function sql_data_seek($what, $result)
  167.     {
  168.         return @mysql_data_seek($what, $result);
  169.     }
  170.  
  171.     public function sql_result($result, $number, $what)
  172.     {
  173.         return @mysql_result($result, $number, $what);
  174.     }
  175. }
  176.  
  177. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement