DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Develop And Production Server On Same Php File

07.22.2010
| 3510 views |
  • submit to reddit
        // same mysql connection file for development and production, or more servers
// can you use the global $_SERVER['HTTP_HOST'] to identify your current active server, simple huh??
// this simple scrip identify your server by address
// if you want more serves, just add a elseif clause

<?php
//first - your development server
if ($_SERVER['HTTP_HOST'] == "127.0.0.1") 
{
$hostname_content = "localhost";
$database_content = "YOUR_DATABASE";
$username_content = "YOUR_USER";
$password_content = "YOUR_PASS";
$conn = mysql_pconnect($hostname_content, $username_content, $password_content) or trigger_error(mysql_error(),E_USER_ERROR); 
}
//second- your production server
else 
{
$hostname_content = "YOUR_PRODUTION_SERVER";
$database_content = "YOUR_PRODUCTION_DATABASE";
$username_content = "YOUR_PRODUCTION_USER";
$password_content = "YOUR_PRODUCTION_PASS";
$conn = mysql_pconnect($hostname_content, $username_content, $password_content) or trigger_error(mysql_error(),E_USER_ERROR); 
}
?>