How to store static information without using a database?

Asked

Viewed 404 times

1

How to store static information without using the database?

For example, let’s say that I have a text on a page, which does not need changes frequently, and to avoid using server resources and/or leave the page loading faster and also with editing options by "fields" as in a database, there is some plugin PHP or something efficient I can do?

  • Do not invent the wheel, at most search by Nosql https://pt.wikipedia.org/wiki/NoSQL

  • The question may not ask for good practice, but it is perfectly valid.

  • Did the answer solve what you were looking to know? Do you think you can accept it now? If not, you need something else to be improved?

3 answers

3

For prototyping or home use (I made a tool for my own use and I don’t want to worry about quality), there is no problem in using a static file on the disk.

A consistent implementation approach for you to store a named set of values that change infrequently is storing everything in a JSON file on disk with the functions json_encode and json_decode.

An example of JSON in a scenario where a page has a text and a title:

{
    "texto": "Conteúdo da página",
    "titulo": "Título da página"
}

The advantage of this is that even file manipulation can be done manually without major risks, since the format is user friendly to be read and modified by humans.

Incidentally, this technique is commonly used in production to read settings, which are usually read-only.

The risk of using files on disk is if you modify the file concurrently, for example if two users tried to update the text at the same time.

The disadvantages of storing files in relation to the database is that it lacks transactional control to ensure integrity and atomicity, logs, data history, flexibility for various queries and so on. In a serious project, always use a database to store important user data, regardless of the type of database used.

3

The best way is to use a database. Use the Sqlite and be happy. He has all the advantages he seeks and none of the disadvantages he does not want. Any other alternative of using files on your own will be worse. Even other banks that work similarly to Sqlite is hardly what you are looking for, although they also work.

In some cases where there is virtually no writing and no columns, no need for processing, can do in normal file. It does not seem to be the case.

An alternative to saving server resources, if you really need it, is to use the database only to store the data to generate the pages statically. If the page changes infrequently, has no dynamic parts (except parts that are loaded on demand in the client) and is accessed very often, create the HTML file when the database update occurs and keep it for static access.

Using PHP will not be efficient. Its resource consumption is worse than using a database. The fewer things you do in PHP, the better. Of course, it’s not always possible. If you really need to, evaluate if you need to have something in a separate file. There are situations that maintenance is so rare and only the programmer will make it worthwhile until you leave everything in PHP code. That’s what Wordpress does with some things. Reinforcement, has cases.

0

There is a difference between Database and Database Management System.

The Database is a collection of database, basically you store all your data in a database, the differential is how you insert, manipulate and remove data from there, this is the role of the Management System (DBMS).

If you want to store data without using a DBMS you will need to create one of your own. This can be summed up in opening a file, writing the data and closing the file, By concentrating you will be squandering the Distributed System properties that some Dbms offer (if not all), in addition to the so-called ACID (relational database) and BASE property (non-relational database or Nosql).

Basically you can have a file just for you to write and leave there in a corner if you want, but be aware that you will need to work mainly in atomicity (protect your data from failures) which will take a lot of work.

My suggestion: use a relational database or a Nosql, see which one best meets your needs, if you’re not using a specific data too much, don’t use it, Dbms are smart enough about it, In the case of the relational database there is the concept of Materialized View, you could take advantage of it. If you’re going to use a die a lot, use it, they’re also smart for it and make it easy to access your data. They also offer ROLES (access privileges), concurrent accesses, Raids, all of which you lose by not using a DBMS, and if you use your own data manipulation method, you would have to teach this to your entire team.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.