Login   Register  
PHP Classes
elePHPant
Icontem

File: config.mysql.inc.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Bimal Poudel  >  MySQL access class  >  config.mysql.inc.php  >  Download  
File: config.mysql.inc.php
Role: Configuration script
Content type: text/plain
Description: mysql connection setup to multple servers for easy portability
Class: MySQL access class
MySQL database access wrapper
Author: By
Last change:
Date: 2009-01-24 05:17
Size: 2,483 bytes
 

Contents

Class file image Download
<?php
/**
* MySQL Database access configurations
* This file must be in the same directory as the parent class.mysql.inc.php is in.
* @author Bimal Poudel
* @copyright 2006, Bimal Poudel
* @package mysql
*/

/**
* @var array Database Connection parameters
*/
$dbinfo = array(); # reset any older settings

/**
* @var string dbindex Get to know, which server index to use.
*/
$dbinfo['dbindex'] = (isset($_SERVER['SERVER_NAME']))?$_SERVER['SERVER_NAME']:((isset($_SERVER['HOSTNAME']))?$_SERVER['HOSTNAME']:"localhost-default");
# Scripts running from the CRON can not have server name.

##################################################################################################
####################[ !THE ONLY MODIFIABLE CODES! ]###############################################
##################################################################################################
/**
* For each possible servers, define the connection parameters.
*/
switch($dbinfo['dbindex'])
{
case 
'sitbim.com':
case 
'www.sitbim.com':
case 
'localhost':
default:
    
$dbinfo[$dbinfo['dbindex']]['host']='localhost';
    
$dbinfo[$dbinfo['dbindex']]['dbuser']='class';
    
$dbinfo[$dbinfo['dbindex']]['dbpassword']='classpassword';
    
$dbinfo[$dbinfo['dbindex']]['database']='class_database';
}

/**
* Based on the actual database index, make an acual database connection.
* Everything will be used as a global value.
*/
define('MYSQL_DATABASENAME'$dbinfo[$dbinfo['dbindex']]['database']);
define('MYSQL_CONNECTION'mysql_connect(
    
$dbinfo[$dbinfo['dbindex']]['host'],
    
$dbinfo[$dbinfo['dbindex']]['dbuser'],
    
$dbinfo[$dbinfo['dbindex']]['dbpassword']
))
or die(
"Cannot connect to the database <STRONG>(".$dbinfo[$dbinfo['dbindex']]['database'].") on ".$dbinfo[$dbinfo['dbindex']]['host']."</STRONG><HR>".mysql_error());

/**
* Use the active mysql database, immediately after the connection is made.
*/
# /* $dbinfo[$dbinfo['dbindex']]['dbcon'] */
/*
mysql_select_db($dbinfo[$dbinfo['dbindex']]['database'], $dbinfo[$dbinfo['dbindex']]['dbcon'])
    or die("Database <strong>(".$dbinfo[$dbinfo['dbindex']]['database'].")</strong> can not be selected.<HR>".mysql_error());
*/
mysql_select_db($dbinfo[$dbinfo['dbindex']]['database'], MYSQL_CONNECTION)
    or die(
"Database <strong>(".$dbinfo[$dbinfo['dbindex']]['database'].")</strong> can not be selected.<HR>".mysql_error());

#define('MYSQL_CONNECTION', $dbinfo[$dbinfo['dbindex']]['dbcon']);

?>