Advertisement
Guest User

Untitled

a guest
May 28th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Videotheek</title>
  6. </head>
  7. <body>
  8.  
  9. <?php
  10. class Database
  11. {
  12. private static $dbName = 'videotheek' ;
  13. private static $dbHost = 'localhost' ;
  14. private static $dbUsername = 'root';
  15. private static $dbUserPassword = 'root';
  16.  
  17. private static $cont = null;
  18.  
  19. public function __construct() {
  20. die('Init function is not allowed');
  21. }
  22.  
  23. public static function connect()
  24. {
  25. // One connection through whole application
  26. if ( null == self::$cont )
  27. {
  28. try
  29. {
  30. self::$cont = new PDO( "mysql:host=".self::$dbHost.";"."dbname=".self::$dbName, self::$dbUsername, self::$dbUserPassword);
  31. }
  32. catch(PDOException $e)
  33. {
  34. die($e->getMessage());
  35. }
  36. }
  37. return self::$cont;
  38. }
  39.  
  40. public static function disconnect()
  41. {
  42. self::$cont = null;
  43. }
  44. }
  45. ?>
  46.  
  47. </body>
  48. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement