Larry Garfield wrote:
On Sunday 26 August 2007, Bruce Cowin wrote:
I'm curious as to how everyone organises and includes their classes in
PHP5.
Then have a config file of some sort in which you specify your DB credentials.
There's a variety of ways to do that (ini file, a PHP file with a database
url, a PHP file that just has a couple of variables in it, or constants
instead, etc.). Pick one you like. Then have your DB connection class read
that file's data one way or another and connect as appropriate.
If you have to modify anything other than a single config file in order to
move your site/app from one server to another, then you have a design flaw.
(I'd say that applies for moving the site to a subdirectory on a server too,
but that takes a bit more effort.)
I'm with Larry on this. Include a constants file at the top of your
scripts. In that file you can place a switch block that tests for the
$_SERVER['HTTP_HOST']. For each case, place something like:
define('DB_NAME', 'my_dev_db');
Other things this is useful for are setting a boolean constant that a
class might test in, eg. a toString method or error handling, and email
addresses for scripts that phone the client. If you have a bunch of
different ones it might be easiest to define dev & test email addresses
first and, in the switch block, set the others accordingly. So, say you
have several email addresses for various things being sent to client
employees (sales@, admin@, jobs@, etc.). You can do something like:
define('EMAIL_DEV', 'me@xxxxxxxxxxxxx');
...
switch($_SERVER['HTTP_HOST'])
{
...
case 'dev.myclient.mycompany.com':
define('MY_APP_DEBUG', TRUE);
define('DB_NAME', 'my_dev_db');
define('EMAIL_SALES', EMAIL_DEV);
define('EMAIL_ADMIN', EMAIL_DEV);
define('EMAIL_JOBS', EMAIL_DEV);
...
break;
No muss. No fuss.
b
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php