0

I want to be able to store website configuration without the use of mysql. I also want the user to be able to change this information from a web page. What's the best methods to do so?

Mat
  • 202,337
  • 40
  • 393
  • 406
Joshwaa
  • 840
  • 1
  • 11
  • 22

4 Answers4

4

Valuable options are a SQLite database, or just a PHP file containing a serialized array if you want a really simple option:

// reading configuration
$config = unserialize(file_get_contents('config'));

// storing configuration
file_put_contents('config', serialize($config));
BenMorel
  • 34,448
  • 50
  • 182
  • 322
  • I want to keep this project as flat-file as possible, and a serialized array is a good idea. – Joshwaa Jun 12 '11 at 16:30
  • A SQLite database is just a flat file containing your database, but it is also more complex for such a simple requirement though! – BenMorel Jun 12 '11 at 16:32
  • Ah, thanks for the info. Any other ways you can think of doing this? I see a lot of sites making "editable settings" but I am aware of them using a MySQL database. I'm trying to keep it flat file b ecause my project only has one database table and i want to distribute it, and i don't want to have to distribute a huge sql file for the people who download it to import into their MySQL database. – Joshwaa Jun 12 '11 at 16:33
  • If you already have a MySQL database for something else, then I would use it for storing the config as well, unless there's a very good reason to do so (and I'm not sure to understand yours!) – BenMorel Jun 13 '11 at 05:19
  • I just don't want to have to distribute a large .sql file with my code, I guess I was being picky. – Joshwaa Jun 14 '11 at 10:22
2

Storing a file is the easiest option. You could store it in plain text, XML, JSON, etc. You might want to try an ini file which can be read/written by PHP - in which case this answer should help.

Community
  • 1
  • 1
Tak
  • 11,428
  • 5
  • 29
  • 48
2

I would use a .ini file format to store configuration. It's human readable in its raw format and fairly easy to parse via PHP (parse_ini_file). A point to note here is that PHP (strangely) doesn't support writing to ini files natively, but if you look at the manual page for parse_ini_file you can find an user submitted example of how do it.

Altough I have not used in PHP projects, YAML (Yet Another Markup Language) seems like a good format to store configuration info (it's pretty much the default config format for rails projects). You can use the syck pecl library to easily read and write stuff in the YAML format

Jay Sidri
  • 6,271
  • 3
  • 43
  • 62
1

You could try cloud based databases if you don't have access to store data on your own server.

glowworms
  • 410
  • 4
  • 8