Every site should have options, changeable via a Control Panel. My new project is going to have this. However, I am curious as to which is the best method for storing these options.
Here are my known methods:
I have tested these, although not very thoroughly, as in all likelihood I will not find the long-term problems or benefits.
Using a MySQL table with fields
key
andvalue
, where each column is a new key/value pair. The downside to this is that MySQL can be slow, and in fact, would require a loop before every page to fetch the options from the database and parse it into an array.Using a MySQL table with a field for each value and a single record. The downside to this is that each new options requires a new field, and this is not the standard use of MySQL tables, but a big benefit is that it requires a single function to bring it into a PHP indexed array.
Using a flat file containing the options array in serialized form, using the PHP functions
serialize
andunserialize
. The main problem with this method is that I would have to first traverse to the file, read in the whole file, and serializing can be slow, so it would get slower as more options are created. It also offers a small layer of obfuscation to the data.Using an ini file. Ini parser's are rather fast, and this options would make it easy to pass around a site configuation. However, as above, I would have to traverse to the ini, and also, using an ini file with PHP is generally unused.
Other formats, such as
XML
andJSON
, have all been considered too. However, they all require some sort of storage, and I am mostly curious about the benefits of each kind of storage.
These are my specific idealistic requirements:
So the basic thing I am looking for is speed, security, and portability. I want the configuration to not be human readable (hence, an unencrypted flat file is bad), be easily portable (ruling out MySQL), and have almost zero but constant performance impact (ruling out most options).
I am not trying to ask people to write code for me, or anything like that. I just need a second pair of eyes on this problem, possibly bringing up points that I never factored in. Thank you for your help
Thank you- Daniel.