Advertisement
Guest User

Untitled

a guest
May 11th, 2017
539
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.97 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.     //
  83.     // Closes database connection an deletes mysqli object
  84.     // -----------------------------------------------------
  85.     //
  86.     public function disconnect()
  87.     {
  88.         @$this->hMySQLi->close();
  89.         unset($this->hMySQLi);
  90.         $this->hMySQLi  = null;
  91.     }
  92.    
  93.     //
  94.     // Returns error and errno if an error occurs
  95.     // -----------------------------------------------------
  96.     // @param   array   error[0] and errno[1]
  97.     //
  98.     public function error()
  99.     {
  100.         if($this->hMySQLi->connect_error)
  101.             return array($this->hMySQLi->connect_error, $this->hMySQLi->connect_errno);
  102.         else
  103.             return array($this->hMySQLi->error, $this->hMySQLi->errno);
  104.     }
  105.    
  106.     //
  107.     // Selects specified default database for querys
  108.     // -----------------------------------------------------
  109.     // @param   string  Database name
  110.     //
  111.     public function dbname($dbName)
  112.     {
  113.         $retVal = @$this->hMySQLi->select_db($dbName);
  114.         $this->debug();
  115.         return $retVal;
  116.     }
  117.    
  118.     //
  119.     // -----------------------------------------------------
  120.     //
  121.     //
  122.     //
  123.     //
  124.     //
  125.     public function query()
  126.     {
  127.    
  128.     }
  129.    
  130.     //
  131.     // -----------------------------------------------------
  132.     //
  133.     //
  134.     //
  135.     //
  136.     public function fetch()
  137.     {
  138.     }
  139.    
  140.     //
  141.     // -----------------------------------------------------
  142.     //
  143.     //
  144.     //
  145.     //
  146.     public function fetchAll()
  147.     {
  148.     }
  149.    
  150.     //
  151.     // Prepares query for execution
  152.     // -----------------------------------------------------
  153.     // @param   string  Query
  154.     //
  155.     public function prepare($query)
  156.     {
  157.         if($this->stmt = $this->hMySQLi->prepare($query))
  158.             return true;
  159.            
  160.         $debug();
  161.         return false;
  162.     }
  163.    
  164.     //
  165.     // Starts transaction if database engine
  166.     // supports it
  167.     // -----------------------------------------------------
  168.     //
  169.     public function transaction()
  170.     {
  171.         $this->hMySQLi->autocommit(false);
  172.     }
  173.    
  174.     //
  175.     // Rollbacks active transaction
  176.     // -----------------------------------------------------
  177.     //
  178.     public function rollback()
  179.     {
  180.         $this->hMySQLi->rollback();
  181.         $this->hMySQLi->autocommit(true);
  182.     }
  183.    
  184.     //
  185.     // Commits active transaction
  186.     // -----------------------------------------------------
  187.     //
  188.     public function commit()
  189.     {
  190.         $this->hMySQLi->commit();
  191.         $this->hMySQLi->autocommit(true);
  192.     }
  193.    
  194.     //
  195.     // Debugging function displays error messages if an error
  196.     // occurs
  197.     // -----------------------------------------------------
  198.     //
  199.     private function debug()
  200.     {
  201.         if($this->debug)
  202.         {
  203.             $error = $this->error();
  204.             if($error[1])
  205.             {
  206.                 echo    "<pre>MySQLi - Debugging Mode:\n------------------------\n";
  207.                 echo    "Error: {$error[0]}\nErrno: {$error[1]}\n\n</pre>";
  208.             }
  209.         }
  210.     }
  211.  
  212. }
  213.  
  214. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement