Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.17 KB | None | 0 0
  1. <?
  2.  
  3. /*
  4. CSc 397b
  5. Instructor: Jesse Gunsch
  6.  
  7. Mark Grandi
  8. 4/7/2011
  9. Final Project - Forum
  10. pdo_db_connection.php
  11. */ 
  12.  
  13.  
  14. class db{
  15.  
  16. /*** Declare instance and other variables***/
  17. private static $instance = NULL;
  18. private static $host = "localhost";
  19. private static $user = "USERNAME";
  20. private static $pass = "PASSWORD";
  21. private static $dbname = "DBNAME";
  22.  
  23. /**
  24. *
  25. * the constructor is set to private so
  26. * so nobody can create a new instance using new
  27. *
  28. */
  29. private function __construct() {
  30.   /*** maybe set the db name here later ***/
  31. }
  32.  
  33. /**
  34. *
  35. * Return DB instance or create intitial connection
  36. *
  37. * @return object (PDO)
  38. *
  39. * @access public
  40. *
  41. */
  42. public static function getInstance() {
  43.  
  44. // only create the PDO object if it hasn't been created yet
  45. if (!self::$instance) {
  46.    
  47.     self::$instance = new PDO("mysql:host=localhost;dbname=kramidna_main", 'kramidna_mark', 'penguinNftsmr4183');  
  48.     self::$instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  49.  
  50.     }
  51. return self::$instance;
  52. }
  53.  
  54. /**
  55. *
  56. * Like the constructor, we make __clone private
  57. * so nobody can clone the instance
  58. *
  59. */
  60. private function __clone(){
  61. }
  62.  
  63. } /*** end of class ***/
  64.  
  65.  
  66. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement