Easy Dev, Debug, and Production Environment

Post Reply
User avatar
jessica
Site Admin
Posts: 31
Joined: Thu Sep 06, 2018 3:17 pm
Location: Cincinnati, Ohio
Contact:

Easy Dev, Debug, and Production Environment

Post by jessica » Wed Sep 12, 2018 5:58 am

I like to create a environment.inc file, inside this file I will have a switch which will test for 3 different conditions PRODUCTION, DEBUG, DEVELOPMENT

Code: Select all

    # Check the environment
    switch (ENVIRONMENT) {
        case "PRODUCTION":{
	        ini_set('display_errors', 0);
	        ini_set('display_startup_errors', 0);
	        error_reporting(NONE);
            break;
        }
        case "DEBUG":{
	        ini_set('display_errors', 1);
	        ini_set('display_startup_errors', 1);
	        error_reporting(E_ALL);
            break;
        }
        case "DEVELOPMENT":{
	        ini_set('display_errors', 1);
	        ini_set('display_startup_errors', 1);
	        error_reporting(E_ALL); 
            break;
        }
        default:{
            break;
        }
    }
Inside my header file, or index.php whatever you would use to load on every page, I will then have a constant called

Code: Select all

define(ENVIRONMENT, "PRODUCTION");
Now where ever you want different actions depending on the environment (such as a test database, for development and debug) you can easily setup throughout your code:

Code: Select all

    if (ENVIRONMENT != "PRODUCTION") {
    	# Production DB calls
    }
    else {
        # Development or Test DB calls
    }
Hope this helps someone.
Post Reply