Question

I'm a Dreamweaver and php noobie (I'm a C++ developer), I'd like to know if there's a way to define different "modes" (e.g. Debug, Release, etc.)? For example, I'd like to be able to have a Debug and Release mode that would affect my database connection and other variables, I'd like to be able to use this in code by doing something like:

if($DEBUGGING)
{ // set connection to debug connection string
}
else
{ // set connection to release connection string
}
Was it helpful?

Solution

http://ca1.php.net/define

header.php

define('DEV_ENV', 'staging');

other files

if( !defined('DEV_ENV') ) { die('error message here'); }

switch(DEV_ENV) {
  case 'production':
    $conn_string = "foo";
    break;
  case 'staging':
    $conn_string = "bar";
    break;
  case 'development':
    $conn_string = "baz";
    break;
  default:
    die('error message here');
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top