toxicious Posted September 2, 2012 Share Posted September 2, 2012 My website needs to do a lot of mysql connections to fetch and insert stuff into a db. In my last "version" of this website I have one file called dblogin.php in which I connect to the db. Then I just do an "include "dblogin.php" (kinda) and then I go on with the stuff. Is there any recommended way of doing this? I mean you want the address, username etc. in one file so you don't have to change it in multiple files if something changes. Link to comment Share on other sites More sharing options...
boen_robot Posted September 2, 2012 Share Posted September 2, 2012 Most applications use a configuration file for this and other environment-dependent settings.Depending on the level of complexity of your application, you could either just include a file with variables/constants, like you're already doing, or you may include a file that returns an array/object that is your configuration, or you might use some sort of configuration file parser for a non-PHP file type (e.g. an ini file, an XML file, etc.).There is no recommended way of doing this, nor is there a most popular convention. Whatever you think will strike the balance between being easier (and flexible enough) for you and others to work with vs. your application easily reading and acting differently based on the configuration. 1 Link to comment Share on other sites More sharing options...
toxicious Posted September 3, 2012 Author Share Posted September 3, 2012 Hmm okay. Thanks a lot for a fast answer! I think having some variables in a file is enough for me then Link to comment Share on other sites More sharing options...
birbal Posted September 3, 2012 Share Posted September 3, 2012 if the setting meant for developer hardcoding it in a php page (like in constants) would be sufficient. if it is large number of setting seprating it in a file would be a good choice. hardcoded settings are faster than loading a file.if the settings is for admin or third person or where is possibility to change the seetings frequently anytime or where you need an interface to edit the setting, storing it seperate file like xml,ini would be best choice. you need to just load the setting everytime. Link to comment Share on other sites More sharing options...
toxicious Posted September 3, 2012 Author Share Posted September 3, 2012 The settings will only be changed by me, so hardcoding them into a separate file is the easiest I think. Since I will use "include .../settings.php" or something like that I hardly doubt that it will affect the performance Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now