Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ## Class cSession()
- ##
- ## Written by Henric Johansson, henric-johansson@hotmail.com 2011-10-19
- ## Takes care of your database setup
- class cDatabase {
- private static $debug = false;
- private static $isInitialized = false;
- public static function debug($debug = true) {
- self::$debug = $debug;
- }
- ## Function to check if we are initialized
- public static function isInitialized() {
- return self::$isInitialized;
- }
- public static function initialize($username, $password, $database, $host) {
- ## Check if we have our variables (Password may be empty in some cases)
- if($username == "" || $database == "" || $host == "") {
- ## Return false
- return false;
- }
- ## Debug check, then connect
- if(self::$debug) {
- $handle = mysql_connect($host, $username, $password) or die ('Could not connect to ' . $host);
- } else {
- $handle = mysql_connect($host, $username, $password);
- }
- ## If you are debugging, tell the user we are connected
- if(self::$debug) {
- echo 'Connected to ' . $host . '<br />';
- }
- ## Check if we are debugging, and if we are, echo out error messages.
- if(self::$debug) {
- if(mysql_select_db($database, $handle)) {
- echo 'Database selected. <br />';
- ## Set isInitialized to true
- self::$isInitialized = true;
- return true;
- } else {
- echo 'Could not select database. <br />';
- }
- } else {
- if(mysql_select_db($database, $handle)) {
- self::$isInitialized = true;
- return true;
- }
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement