开发者

Using SQLite for configuration management

开发者 https://www.devze.com 2022-12-19 23:33 出处:网络
I\'mdeveloping 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 coupl

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
?>
0

精彩评论

暂无评论...
验证码 换一张
取 消