Jump to content

What settings to define?


Pain

Recommended Posts

Hi. I'm curious what settings/other things are people usually defining to make their lives a bit easier (i'm talking about constants)?

 

And if possible please give an explanation (why is it useful to define a particular constant).

 

As you can see my list is nothing special, therefore I'm looking forward to hearing what you have to say.

...
define("DB_HOST", "localhost");
define("DB_USER", "user");
define("DB_PASS", "pass");
define("DB", "db_name");
define("BASE_URL", "http://www.something.com");
...

Thanx:)

Edited by Pain
Link to comment
Share on other sites

My personal opinion is that you should never define a constant that isn't absolutely going to be the same value throughout the application, because it is global in scope. For instance, even your DB connection params might change, because it is possible (and common) to connect to more than one database. I'll usually define a WEBSITE_NAME and an ENVIRONMENT constant. I usually define a constant that is the path to the front controller (index.php). It's pretty common to store most of the website configuration in config files. Check out most of the popular PHP frameworks and you'll usually see them stored in arrays.

Link to comment
Share on other sites

1 - I have no constants defined.

2 - For the material you presented, the solution is to make a small module of the logon code that you use in any script that needs a db connection by 'include-ing' it.  No need for a constant there either.

 

Of course somebody else is going to refute this practice but to each their own.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.