RaiN3772 Posted July 20, 2022 Share Posted July 20, 2022 hello there, i want to fetch settings from database and use them in most of the files in the project, e.g website_name i would like to get it from the database and put it in the <title> tag. why i want to use the database instead of the php or ini file is so i can edit the settings from the web and not the file. i already know how to fetch the data from the database and use it, but my question is what is the best practice to do so. should i fetch all the data at once and use foreach loop in the core file of the project or should i use a class or something, im really lost. because most apps/forum use database settings such as mybb for example where u can edit the settings directly from the app but i dont know how to do it in a class, if someone could show me an example code i would really appreciate it. Thank you Quote Link to comment https://forums.phpfreaks.com/topic/315063-load-configsettings-from-database/ Share on other sites More sharing options...
requinix Posted July 20, 2022 Share Posted July 20, 2022 The question is do you want your entire website to be completely broken if you have a database issue? I mean, not even able to render an error page? Basic configurations are typically done in files because they're far more reliable, not to mention easier to modify and faster to read. Is there a particular reason you'd like to do a database instead? 1 Quote Link to comment https://forums.phpfreaks.com/topic/315063-load-configsettings-from-database/#findComment-1598420 Share on other sites More sharing options...
RaiN3772 Posted July 21, 2022 Author Share Posted July 21, 2022 11 hours ago, requinix said: The question is do you want your entire website to be completely broken if you have a database issue? I mean, not even able to render an error page? Basic configurations are typically done in files because they're far more reliable, not to mention easier to modify and faster to read. Is there a particular reason you'd like to do a database instead? so what are you saying that i should create an ini or json file and when i want to edit some settings i should just use open/write? there is no reason for the database, i just dont want messy code/more files, just looking for the best practical coding solution. Quote Link to comment https://forums.phpfreaks.com/topic/315063-load-configsettings-from-database/#findComment-1598435 Share on other sites More sharing options...
requinix Posted July 21, 2022 Share Posted July 21, 2022 2 hours ago, RaiN3772 said: so what are you saying that i should create an ini or json file and when i want to edit some settings i should just use open/write? More or less. What sorts of settings are you thinking about? Files are more suited for things that you don't really ever need to change, like the name of the website or its domain name, not to mention "obvious" configuration stuff like database information and credentials. 2 hours ago, RaiN3772 said: there is no reason for the database, i just dont want messy code/more files, just looking for the best practical coding solution. What's "most practical" really depends on what you need to do, and how often... Quote Link to comment https://forums.phpfreaks.com/topic/315063-load-configsettings-from-database/#findComment-1598436 Share on other sites More sharing options...
RaiN3772 Posted July 21, 2022 Author Share Posted July 21, 2022 Great, Thanks alot @requinix Quote Link to comment https://forums.phpfreaks.com/topic/315063-load-configsettings-from-database/#findComment-1598437 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.