Advertisement
Guest User

Untitled

a guest
Apr 17th, 2016
106
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.  
  3. class DB {
  4.  
  5. private static $_MYSQL_HOST="localhost";
  6. private static $_MYSQL_USER="your_mysql_user";
  7. private static $_MYSQL_PASS="your_mysql_password";
  8. private static $_MYSQL_DB="your_mysql_database";
  9.  
  10. private static $connect = null;
  11.  
  12. public function __construct() {
  13. die('Init function is not allowed');
  14. }
  15.  
  16. public static function connect()
  17. {
  18. if ( null == self::$connect )
  19. {
  20. try
  21. {
  22. self::$connect = new PDO( "mysql:host=".self::$_MYSQL_HOST.";"."dbname=".self::$_MYSQL_DB, self::$_MYSQL_USER, self::$_MYSQL_PASS);
  23. }
  24. catch(PDOException $exception)
  25. {
  26. die($exception->getMessage());
  27. }
  28. }
  29. return self::$connect;
  30. }
  31.  
  32. public static function disconnect()
  33. {
  34. self::$connect = null;
  35. }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement