Advertisement
Guest User

Untitled

a guest
May 10th, 2017
555
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.85 KB | None | 0 0
  1. <?php
  2.  
  3. //           _____    
  4. //  ___ _ __|___ /_  __
  5. // / __| '_ \ |_ \ \/ /
  6. // \__ \ |_) |__) >  <
  7. // |___/ .__/____/_/\_\
  8. //     |_| info@sp3x.de
  9. //
  10. // @author sp3x
  11. // @copyright sp3x / sp3x.de
  12. // @license All rights reserved
  13. // @version $Revision 1 $
  14. // @date $17.09.2009 $
  15. //
  16.  
  17. class Database
  18. {
  19.  
  20. //
  21. // MySQLi Object
  22. // @var mysqli
  23. //
  24. private $hMySQLi;
  25.  
  26. //
  27. // Debugging mode
  28. // @var boolean
  29. //
  30. private $debug;
  31.  
  32. //
  33. // MySQLi Result object
  34. // @var MySQLi::Result
  35. //
  36. private $result;
  37.  
  38. //
  39. // MySQLi Statement object
  40. // @var MySQLi::STMT
  41. //
  42. private $stmt;
  43.  
  44. //
  45. // Parameters for prepared statements
  46. // @var array
  47. //
  48. private $params;
  49.  
  50.     //
  51.     // Database constructor
  52.     // -----------------------------------------------------
  53.     // @param   boolean Debugging
  54.     //
  55.     public function __construct($debug = false)
  56.     {
  57.         $this->debug = $debug;
  58.     }
  59.    
  60.     //
  61.     // Connect to mysql database
  62.     // -----------------------------------------------------
  63.     // @param   string  Hostname
  64.     // @param   string  Username
  65.     // @param   string  Password
  66.     // @param   integer Port
  67.     // @param   boolean Persistente connection
  68.     //
  69.     public function connect($host = '127.0.0.1', $user = 'root', $pass = '', $port = 3306,
  70.         $pconn = false)
  71.     {
  72.         if($pconn)
  73.             $host = 'p:'.$host;
  74.         $this->hMySQLi = @new mysqli($host, $user, $pass, '', $port);
  75.         if(!$this->hMySQLi->connect_error)
  76.             return true;
  77.            
  78.         $this->debug();
  79.         return false;
  80.     }
  81.    
  82.     public function disconnect()
  83.     {
  84.         @$this->hMySQLi->close();
  85.         unset($this->hMySQLi);
  86.         $this->hMySQLi  = null;
  87.     }
  88.    
  89.     //
  90.     // Returns error and errno if an error occurs
  91.     // -----------------------------------------------------
  92.     // @param   array   error[0] and errno[1]
  93.     //
  94.     public function error()
  95.     {
  96.         if($this->hMySQLi->connect_error)
  97.             return array($this->hMySQLi->connect_error, $this->hMySQLi->connect_errno);
  98.         else
  99.             return array($this->hMySQLi->error, $this->hMySQLi->errno);
  100.     }
  101.    
  102.     //
  103.     // Selects specified default database for querys
  104.     // -----------------------------------------------------
  105.     // @param   string  Database name
  106.     //
  107.     public function dbname($dbName)
  108.     {
  109.         $retVal = @$this->hMySQLi->select_db($dbName);
  110.         $this->debug();
  111.         return $retVal;
  112.     }
  113.    
  114.     //
  115.     // -----------------------------------------------------
  116.     //
  117.     //
  118.     //
  119.     //
  120.     //
  121.     public function query()
  122.     {
  123.    
  124.     }
  125.    
  126.     //
  127.     // -----------------------------------------------------
  128.     //
  129.     //
  130.     //
  131.     //
  132.     public function fetch()
  133.     {
  134.     }
  135.    
  136.     //
  137.     // -----------------------------------------------------
  138.     //
  139.     //
  140.     //
  141.     //
  142.     public function fetchAll()
  143.     {
  144.     }
  145.    
  146.     //
  147.     // Prepares query for execution
  148.     // -----------------------------------------------------
  149.     // @param   string  Query
  150.     //
  151.     public function prepare($query)
  152.     {
  153.         if($this->stmt = $this->hMySQLi->prepare($query))
  154.             return true;
  155.            
  156.         $debug();
  157.         return false;
  158.     }
  159.    
  160.     //
  161.     // Starts transaction if database engine
  162.     // supports it
  163.     // -----------------------------------------------------
  164.     //
  165.     public function transaction()
  166.     {
  167.         $this->hMySQLi->autocommit(false);
  168.     }
  169.    
  170.     //
  171.     // Rollbacks active transaction
  172.     // -----------------------------------------------------
  173.     //
  174.     public function rollback()
  175.     {
  176.         $this->hMySQLi->rollback();
  177.         $this->hMySQLi->autocommit(true);
  178.     }
  179.    
  180.     //
  181.     // Commits active transaction
  182.     // -----------------------------------------------------
  183.     //
  184.     public function commit()
  185.     {
  186.         $this->hMySQLi->commit();
  187.         $this->hMySQLi->autocommit(true);
  188.     }
  189.    
  190.     //
  191.     // Debugging function displays error messages if an error
  192.     // occurs
  193.     // -----------------------------------------------------
  194.     //
  195.     private function debug()
  196.     {
  197.         if($this->debug)
  198.         {
  199.             $error = $this->error();
  200.             if($error[1])
  201.             {
  202.                 echo    "<pre>MySQLi - Debugging Mode:\n------------------------\n";
  203.                 echo    "Error: {$error[0]}\nErrno: {$error[1]}\n\n</pre>";
  204.             }
  205.         }
  206.     }
  207.  
  208. }
  209.  
  210. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement