Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1.  
  2.  
  3. <?php
  4. //declare constants
  5. define("HOME_HOST_NAME", "localhost");
  6. define("HOME_USER_NAME", "s_smithb");
  7. define("HOME_PASSWORD", "5jfzwkxf7");
  8. define("HOME_DB_NAME", "localhost");
  9. define("ACC_HOST_NAME", "driftwood.sunyacc.edu");
  10. define("ACC_USER_NAME", "s_smithb");
  11. define("ACC_PASSWORD", "5jfzwkxf7");
  12. define("ACC_DB_NAME", "s_smithb");
  13.  
  14. function DB_Connect()
  15. {
  16. //initialize connect variables
  17. //contingent on where running
  18. if($_SERVER['HTTP_HOST'] == 'localhost')
  19. {
  20. $hostName = HOME_HOST_NAME;
  21. $userName = HOME_USER_NAME;
  22. $password = HOME_PASSWORD;
  23. $dbName = HOME_DB_NAME;
  24. }//end if
  25. elseif($_SERVER['HTTP_HOST'] == "driftwood.sunyacc.edu")
  26. {
  27. $hostName = ACC_HOST_NAME;
  28. $userName = ACC_USER_NAME;
  29. $password = ACC_PASSWORD;
  30. $dbName = ACC_DB_NAME;
  31. }//end else if
  32.  
  33. //connect to server and verify success
  34. $serverConnect = mysql_connect($hostName, $userName, $password);
  35. if($serverConnect === false)
  36. {
  37. printf("ERROR - Unable to connect to server $hostname. " .
  38. "Error code: %s\n", mysql_error());
  39. exit;
  40. }//end if
  41.  
  42. //connect to database and verify success
  43. $dbResult = mysql_select_db($dbName);
  44. if(!$dbResult)
  45. {
  46. printf("ERROR - Unable to connect to database $dbName. " .
  47. "Error code: %s\n", mysql_error());
  48. exit;
  49. }//end if
  50. return $serverConnect; //return the connection resource
  51. }//end fn
  52. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement