Database config for localhost and server

To easily toggle database config for localhost and server, you can simply check whether you are accessing the local or server.

1
2
3
4
5
6
7
8
9
10
11
12
13
if (preg_match("/localhost/i", $_SERVER['SERVER_NAME'])) {
define ('DBHOST','localhost');
define ('DBNAME','localdbname'); 
define ('DBUSER','localuser');
define ('DBPASS','localpass');
define ('DEV',TRUE);
} else {
define ('DBHOST','localhost');
define ('DBNAME','serverdbname'); 
define ('DBUSER','serveruser');
define ('DBPASS','serverpass');
define ('DEV',FALSE);
}

Leave a Reply

Your email address will not be published. Required fields are marked *