Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. <?php
  2. class Database
  3. {
  4. private static $dbName = 'angular';
  5. private static $dbHost = 'localhost';
  6. private static $dbUsername = 'root';
  7. private static $dbUserPassword = '';
  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. // One connection through whole application
  17. if ( null == self::$cont ) {
  18. try {
  19. self::$cont = new PDO( "mysql:host=".self::$dbHost.";"."dbname=".self::$dbName, self::$dbUsername, self::$dbUserPassword);
  20. }
  21. catch(PDOException $e) {
  22. die($e->getMessage());
  23. }
  24. }
  25. return self::$cont;
  26. }
  27.  
  28. public static function disconnect() {
  29. self::$cont = null;
  30. }
  31. }
  32. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement