Reputation: 159
I´m developing a CMS that will be used by multiple companies. So, each user would have some personal preferences and settings.
Searching in the forum i found out that store the config settings in a .ini file could be a good way to go... But in my case, each user will have the option to change their own settings whenever he want.
Keeping in mind that each user would have like 30 to 50 options stored (just some variables/values or a few arrays), and each user will have their own database, but all the files will be shared in the same server.
So, i was wondering what is the best way...
1) DATABASE:
To create a "config" table that would store each setting as a row, and the application would access database everytime to load the settings; something like that:
row 1 -> var = "user_logo_url" // type = "string" // value = "http://exemple.com/logo.jpg"
row 2 -> var = "some_array_value" // type = "array" // value = "serialized value here"
2) XML:
Store the data into a xml file and parse it to load the configurations (or maybe load at the login and store it in the $_SESSION.
3) DATABASE and fwrite a INI or PHP file:
Ok, that one i even know if it´s possible, but it´s about to store all the settings in database (to easy manage) and then use fwrite to save the settings as variables in a php file, and than, to have a better performance on loading the settings.
I´m pretty new on php, so i don´t know what is the best way considering the performance of the application, and would appreciate any help for this!
If i was not clear in something please let me know!
Thanks!
Upvotes: 2
Views: 2763
Reputation: 30
Btw you can just save on db and when you gonna load, you load in a global var and save there the database request (web name etc), or make constant connection with db or even by ini file (use php .ini parse). In lacks of performance it will be likely the same because they will have to load, but if you have website which some configs just need to be loaded 1 time, you can connect db -> storage on var and use that var for what you need
Upvotes: 0
Reputation: 9432
I store settings as a json string,try it out...search json_encode and json_decode
Upvotes: 2
Reputation: 692
I would personally use a database. Just create a table called "config" (or something similar) with two fields: configId varchar(100), configValue varchar(255) (or type text if you anticipate a lot of data).
PHP arrays can be serialized or you can use implode()
to join them together with a separator (to be later re-separated using explode()
).
Example:
$value = array("one", "two", "three");
$configValue = implode("|", $value);
$configValue
will return: "one|two|three"
as a single string. Using $value = explode("|", $configValue);
will reverse the process.
Upvotes: 1