Guest User

Untitled

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