Pain Posted March 15, 2014 Share Posted March 15, 2014 (edited) 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 March 15, 2014 by Pain Quote Link to comment Share on other sites More sharing options...
sKunKbad Posted March 15, 2014 Share Posted March 15, 2014 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. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted March 15, 2014 Share Posted March 15, 2014 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. Quote Link to comment Share on other sites More sharing options...
Ansego Posted March 15, 2014 Share Posted March 15, 2014 I use them when ever I need to use them multiple times throughout the code. If I use something once or even twice I don't normally use unless it is for security and I am placing them outside the root of my web. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.