Using SQLite for configuration management
I'm developing a PHP application where I have to store configuration variables.
Using MySQL would be overkill, because it's a C开发者_如何学PythonLI app I'm talking about and there are only a couple of configuration variables.
I don't know about INI files... I'm thinking of using SQLite.
What do you think? It is too overkill using SQLite? Do you suggest using other approaches?
That really depends on how large your configuration files are going to be and how many of them you are going to store.
PHP handles ini files quite well and it seems to be a popular choice amongst PHP frameworks.
Other popular approaches:
- XML
- YAML
- files containing JSON
For the configuration values I would suggest you to use INI files and handle it with parse_ini_file function which is a lot more easier way than resorting to SQLlite.
Consider serializing/unserializing an array for small configuration settings:
<?php
# create settings array
$settings = array(
'setting1' => 'on',
'setting2' => 'off',
'setting3' => true,
);
# save it
$filename = 'settings.txt';
file_put_contents($filename,serialize($settings));
# retrieve it
$getSettings = unserialize(file_get_contents($filename));
# modify it
$getSettings['addedLater'] = 'new value';
# save it again.
file_put_contents($filename,serialize($getSettings));
# rise and repeat
?>
精彩评论