Jump to content

DB, file or other? Best way to store some simple user data


Recommended Posts

I fully admit there's a lot out there that I don't know I don't know as for PHP advancements. So I'm looking for some leads on some simple data storage.


My script will apply a configuration to an interface. I want the ability to save those configs as templates that can later be easily applied. So I'm looking to store a name and a few parameters, most numeric.


I'll need to manage name conflicts and have the ability to delete templates. I probably won't even have an update functionality and just have the users delete and add new when they need to make changes.


The API will be expected to return a list of templates that JavaScript will use to populate a drop-down. Selecting a value will fill a form with values to be applied. There'll be a list of existing templates with delete buttons. Deleting one will need to update the drop-down.


Based on what I do know, I'd handle this with a flat file and delimited values. API would read the file, create an array and send that as a json encoded response. GET, POST (new template) and DELETE requests would act accordingly.


I don't see the need for a database, but I'm thinking of MySQL when I say that.


So what are your thoughts? What don't I know that I should?



Link to comment
Share on other sites

What is the nature of the config/template data? I mean, is it like a config file you'd find in Linux, or is it a set of key/value pairs, or what? As for what's inside each config, how do you know what that's supposed to be like? For example, how do you know what config "options" are valid, and what sorts of values (string, int, etc.) each one uses?

Link to comment
Share on other sites

A name for the template and a few numeric values for delay, loss and rate.


Name, 500, "ms", 100, "ms", 5, 12, "mbit"


If I apply a template, I'll need all of those values. Some values are optional, though, so with a file, I'd have to list "null" or zero values.


I'll never need to do any queries looking for certain values of parameters. Just all or nothing view, apply, delete options through the API.


Does that help?

Link to comment
Share on other sites

If I were to write them as an array, it'd be


$template["name"] = {"delay"=>500, "delay_unit"=>"ms", "loss"=>5}


Template may have one parameter or 10.


Forgive the syntax, as that's probably wrong. Hopefully you get the idea.

Link to comment
Share on other sites

Do all configs have those same "keys" (delay, loss, rate, etc.) and the only difference between them is whether a value is optional and/or what the default is?


In other words, could all possible templates and configs be represented in a single database table?

name | delay | delay_unit | loss | abc  | def
 Foo |   500 |         ms |    5 |   12 | mbit
Name |   500 |         ms |    5 | NULL | NULL
If so then a database table is the way to go. If not then it still might be but I'm not clear on what the differences can be.
Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.