Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Basti0208's avatar

Save Parameters/Settings in Database

Hi, I have a architecture decision to make. In my head I have two ideas on how to store settings/parameters in the database. An example for one of those settings is a treshold in days for the next device maintenance.

I would like to access the settings with a helper class like so

SettingsHelper::get('moduleName', 'settingKey', 'default');

My ideas:

  1. Use a table which contains a key and a value field. The value field has the json type and is not nullable.
  2. Use a table which contains a key and multiple columns for different datatypes which are automatically casted. As example for the columns: string_value and date_value. Those fields are nullable. If I would use this approach I need to define somewhere which setting uses which datatype (a datatype mapping) or I could just specify the datatype in the call for the get method.

Which approach is better and why?

Best regards

0 likes
4 replies
Basti0208's avatar

@jlrdw Would you also not recommend json if the json string would look like this:

{
  "value": "test"
}

or like this:

{
  "value": ["entry1", "entry2"]
}

Laravel could cast those properties automatically, right?

I think the settings are not that big and I would only store one value per setting entry.

Basti0208's avatar
Basti0208
OP
Best Answer
Level 1

I've decided to use the second approach with multiple columns for different data types. I followed @tray2 and @jlrdw recommendations to don't use json column for this type of problem. Thank you for the help!

Please or to participate in this conversation.