Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to save a single value on server

Tags:

php

mysql

server

I am creating an application with a click to call button on an html page.

There will be one person manning the phone. I want this person to be able to set a variable with a boolean value on my server: 1 is available, 0 is unavailable.

I could create a single field SQL table but this feels like overkill, or I could read and write to a text file containing just one character.

What is the most correct way to store a single value?

like image 278
grateful Avatar asked May 23 '16 11:05

grateful


3 Answers

I know it seems like overkill to use a small database table for this.

If your application already uses a database, this is by far the best way to proceed. Your database technology has all kinds of support for storing data so it doesn't get lost. But, don't stand up a database and organize your application to use it just for this one data point; a file will be easier in that case.

(WordPress does something similar; it uses a table called wp_options containing a lot of one-off settings values.)

I suggest your table contain two columns (or maybe more), agent_id and available. Then, if you happen to add another person taking telephone calls, your app will be ready to handle that growth. Your current person can have agent_id = 0.

like image 173
O. Jones Avatar answered Nov 20 '22 12:11

O. Jones


If you have a DB set up, I'd use it.

That's what DB's are for, persisting changeable data.. otherwise you are basically writing your own separate DB system for the sake of one setting, which would be uberkill in my eyes!

There is value in consistency and flexibility.. what if I suddenly need to store an expected return time? How do I do this in a text-file, how do I differentiate the column? How do I manipulate the data? MySQL already answers all these questions for you.

As a team member, I'd expect most of my dev colleagues (and new hires) to know how to use MySQL.. I wouldn't want them to have to work with, extend or debug a separate bespoke file persistence system that I had tacked on.

If you are worried about having lots of one row tables dotted about, you could use a single table for miscellaneous singular config variables which need updating regularly.

We have a table like this:

Table: `setting` 
Columns: `key_string` VARCHAR, `value` VARCHAR

And could store your variable as

['key_string' => 'telephone_service_available', 'value' => '1']
like image 21
Arth Avatar answered Nov 20 '22 13:11

Arth


In this specific case a simple file check (Exist a file or not) is probably the most simple way you can do here. And it also has the benefit to easily check if the file exist or not, you don't have to read file contents. But if you need just one more information, you have to go a complete other way.

like image 1
Brain Foo Long Avatar answered Nov 20 '22 13:11

Brain Foo Long