SHARE
TWEET

Untitled

a guest Oct 19th, 2011 152 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. ## Class cSession()
  4. ##
  5. ## Written by Henric Johansson, henric-johansson@hotmail.com 2011-10-19
  6. ## Takes care of your database setup
  7.  
  8. class cDatabase {
  9.         private static $debug = false;
  10.         private static $isInitialized = false;
  11.  
  12.         public static function debug($debug = true) {
  13.                 self::$debug = $debug;
  14.         }
  15.  
  16.         ## Function to check if we are initialized
  17.         public static function isInitialized() {
  18.                 return self::$isInitialized;
  19.         }
  20.  
  21.         public static function initialize($username, $password, $database, $host) {
  22.  
  23.                 ## Check if we have our variables (Password may be empty in some cases)
  24.                 if($username == "" || $database == "" || $host == "") {
  25.                         ## Return false
  26.                         return false;
  27.                 }
  28.  
  29.                 ## Debug check, then connect
  30.                 if(self::$debug) {
  31.                         $handle = mysql_connect($host, $username, $password) or die ('Could not connect to ' . $host);
  32.                 } else {
  33.                         $handle = mysql_connect($host, $username, $password);
  34.                 }
  35.  
  36.                 ## If you are debugging, tell the user we are connected
  37.                 if(self::$debug) {
  38.                         echo 'Connected to ' . $host . '<br />';
  39.                 }
  40.  
  41.                 ## Check if we are debugging, and if we are, echo out error messages.
  42.                 if(self::$debug) {
  43.                         if(mysql_select_db($database, $handle)) {
  44.                                 echo 'Database selected. <br />';
  45.  
  46.                                 ## Set isInitialized to true
  47.                                 self::$isInitialized = true;
  48.                                 return true;
  49.                         } else {
  50.                                 echo 'Could not select database. <br />';
  51.                         }
  52.                 } else {
  53.                         if(mysql_select_db($database, $handle)) {
  54.                                 self::$isInitialized = true;
  55.                                 return true;
  56.                         }
  57.                 }
  58.         }
  59. }
  60.  
  61. ?>
  62.  
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top