How to store static information without using a database?

0

How do I store static information without using the database?

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

    
asked by anonymous 19.06.2016 / 15:40

3 answers

2

The best way is to use a database. Use SQLite and be happy. It has all the advantages it seeks and none of the disadvantages it does not want. Any other alternative to using files on their own will be worse. Even other banks that work in a way that is analogous to SQLite is hardly what you are looking for, though they may also work.

In some cases where it practically has no writing and no columns, it does not need processing, it can do in normal file. That does not seem to be the case.

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

Using PHP will not be efficient. His resource consumption is worse than using a database. The less things you do in PHP, the better. Of course, that is not always possible. If necessary, evaluate whether you need to have something on a separate file. It has situations that maintenance is so rare and only the programmer will make it pay off until you leave everything in the PHP code itself. That's what WordPress does with some things. Reinforcement, there are cases.

    
19.06.2016 / 16:11
2

For prototyping or home use (I made a tool for myself and do not 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 to store everything in a JSON file on disk with json_encode and json_decode .

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

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

The advantage of this is that even the manipulation of the file can be done manually without great risks, since the format is 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 attempted to update the text at the same time.

The disadvantages of storing in files relative to the database is lacking 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 bank used.

    
01.07.2016 / 04:35
0

There is a difference between Database and System Database Manager.

The Database is a database collection, basically you store all your data in a database, the differential is how you insert, manipulate and pull data from there, this is the role of the System Manager ( 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, but you will be wasting the Distributed System properties that some (if not all) of the SGBDs offer, in addition to the so-called ACID (relational database) and BASE ( non-relational database or NoSQL).

Basically you can have a file just for you to write and leave it there in a little corner if you want, but be aware that you need to work mainly on atomicity (protect your data from crashes)

My suggestion: use a relational database or a NoSQL, see what best suits your needs, if you do not use a specific data, do not use, the DBMSs are smart enough about it, In the case of the relational database there is the concept of Materialized View, you could take advantage of this. If you are going to use a lot a lot frequently, use it, they are also smart for it and facilitates access to your die. 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 method of data manipulation, you would have to teach this to your entire team .

    
19.06.2016 / 16:28