Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML or Database Table to store settings

I am about to start writing a site in PHP using MySQL as back-end. One of the first decisions that I have to make is whether to store site settings in a database table or in a XML file. I thought about storing them as key/value pairs, no matter which storage I use. It's probably the most flexible and best way to do it.

Since both ways are relatively simple to implement and use, my worries are about performance. Which one is faster ? Which one should I use ? Why ?

PS: How easy would it be to store the settings in an .ini file ? Can they be changed easily by a PHP script rather than manually by the user/sysadmin ?

Also, if I would store the settings in a mysql table, the sysadmin can easily cache that (very small) table in RAM. Can he do that with an XML file ?

like image 524
Radu Murzea Avatar asked Sep 04 '26 02:09

Radu Murzea


2 Answers

I assume the configuration is per user. Firstly I would suggest you to write a wrapper class which will access the configuration. That way you could only change the core of configuration in one class not in all code.

class configuration {
  public function get_user_configuration() {
    // return users configuration
  }
}

I think it would be easier to store configuration in database. Because then the configuration probably will be backed up daily and can be easily exported.

Caching this configuration is a good idea. The easiest way would be to cache it in session. You could also try memcache or APC.

like image 154
Martins Balodis Avatar answered Sep 05 '26 17:09

Martins Balodis


In any case, storing it in the DB makes sense. You can still cache it to a (XML) file when settings have changed if you want and load that file instead. So the application will never query the DB for the settings.

like image 25
DanMan Avatar answered Sep 05 '26 18:09

DanMan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!