Advertisement
Five_NT

db_connect

Apr 3rd, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. <?php
  2. class Connection {
  3.     private static $DB_HOST = 'fenrir.info.uaic.ro';
  4.     private static $DB_NAME = 'twebDB';
  5.     private static $DB_USER = 'twebDB';
  6.     private static $DB_PASS = 'MtFjuUtw2J';
  7.    
  8.     private static $dbInstance;
  9.    
  10.     private function __construct() {}
  11.    
  12.     public static function openConnection() {
  13.         if(!isset(self::$dbInstance)) {
  14.             // instantiem obiectul MySQL, via constructorul care va realiza conectarea la serverul MySQL
  15.             $conn = new mysqli (
  16.                 self::$DB_HOST, // locatia serverului (aici, masina locala)
  17.                 self::$DB_USER, // numele de cont
  18.                 self::$DB_PASS, // parola (atentie, in clar!)
  19.                 self::$DB_NAME  // baza de date
  20.                 );
  21.             if($conn->connect_error) {
  22.                 header("Location: notfound.php");
  23.                 die();
  24.             }
  25.                
  26.         }
  27.     }
  28.    
  29.     public static function closeConnection() {
  30.         if(isset(self::$dbInstance)) {
  31.             self::$dbInstance->close();
  32.             self::$dbInstance = null;
  33.         }
  34.     }
  35.    
  36.     // inchidem conexiunea cu serverul MySQL
  37.     //mysqli_close($mysql);
  38. }
  39.  
  40.  
  41. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement