Advertisement
Guest User

Untitled

a guest
Jan 12th, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. <?php
  2. class Database
  3. {
  4. /**
  5. * Déclarations variables connexion à la base de données
  6. */
  7.  
  8. private static $dbhost = "localhost";
  9. private static $dbName = "france";
  10. private static $dbUsername = "root";
  11. private static $dbUserPassword = "";
  12.  
  13. private static $connection = NULL;
  14.  
  15. public static function connect() {
  16. if (self::$connection == NULL) {
  17. try {
  18. self::$connection = new PDO("mysql:host=" . self::$dbhost . "; dbName =" . self::$dbName, self::$dbUsername, self::$dbUserPassword);
  19. self::$connection -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  20. }
  21. catch (PDOException $e) {
  22. die($e -> getMessage());
  23. }
  24. }
  25. return self::$connection;
  26. }
  27.  
  28. public static function disconnect() {
  29. self::$connection = NULL;
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement