Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- /*
- CSc 397b
- Instructor: Jesse Gunsch
- Mark Grandi
- 4/7/2011
- Final Project - Forum
- pdo_db_connection.php
- */
- class db{
- /*** Declare instance and other variables***/
- private static $instance = NULL;
- private static $host = "localhost";
- private static $user = "USERNAME";
- private static $pass = "PASSWORD";
- private static $dbname = "DBNAME";
- /**
- *
- * the constructor is set to private so
- * so nobody can create a new instance using new
- *
- */
- private function __construct() {
- /*** maybe set the db name here later ***/
- }
- /**
- *
- * Return DB instance or create intitial connection
- *
- * @return object (PDO)
- *
- * @access public
- *
- */
- public static function getInstance() {
- // only create the PDO object if it hasn't been created yet
- if (!self::$instance) {
- self::$instance = new PDO("mysql:host=localhost;dbname=kramidna_main", 'kramidna_mark', 'penguinNftsmr4183');
- self::$instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- }
- return self::$instance;
- }
- /**
- *
- * Like the constructor, we make __clone private
- * so nobody can clone the instance
- *
- */
- private function __clone(){
- }
- } /*** end of class ***/
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement