Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //declare constants
- define("HOME_HOST_NAME", "localhost");
- define("HOME_USER_NAME", "s_smithb");
- define("HOME_PASSWORD", "5jfzwkxf7");
- define("HOME_DB_NAME", "localhost");
- define("ACC_HOST_NAME", "driftwood.sunyacc.edu");
- define("ACC_USER_NAME", "s_smithb");
- define("ACC_PASSWORD", "5jfzwkxf7");
- define("ACC_DB_NAME", "s_smithb");
- function DB_Connect()
- {
- //initialize connect variables
- //contingent on where running
- if($_SERVER['HTTP_HOST'] == 'localhost')
- {
- $hostName = HOME_HOST_NAME;
- $userName = HOME_USER_NAME;
- $password = HOME_PASSWORD;
- $dbName = HOME_DB_NAME;
- }//end if
- elseif($_SERVER['HTTP_HOST'] == "driftwood.sunyacc.edu")
- {
- $hostName = ACC_HOST_NAME;
- $userName = ACC_USER_NAME;
- $password = ACC_PASSWORD;
- $dbName = ACC_DB_NAME;
- }//end else if
- //connect to server and verify success
- $serverConnect = mysql_connect($hostName, $userName, $password);
- if($serverConnect === false)
- {
- printf("ERROR - Unable to connect to server $hostname. " .
- "Error code: %s\n", mysql_error());
- exit;
- }//end if
- //connect to database and verify success
- $dbResult = mysql_select_db($dbName);
- if(!$dbResult)
- {
- printf("ERROR - Unable to connect to database $dbName. " .
- "Error code: %s\n", mysql_error());
- exit;
- }//end if
- return $serverConnect; //return the connection resource
- }//end fn
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement