简体   繁体   中英

Storing small amounts of dynamic data on website

Try to imagine a site with a greeting or catch phrase that is shown on a home page that can be edited or changed by the site owner. What is the best way to store small amounts of data like that? I am currently using a database to store very complex data, but it seems very wasteful to make a whole new table just so that i can store and retrieve a single row.

What are good practices for such use cases? If it is of any use, I'm currently using a LAMP stack with a Laravel framework

If you already use a database, I don't see why it would be wasteful to store this in it. Alternatively, you can have a config file in json, yaml or any type you prefer and read the data from there. However, your client probably can manage the data easier if you use the database and provide the option to change it in an admin area.

As I see it you only have one other option if you don't want to use database. A text file.

I agree with cmorrissey. Text files has a issue in php, they can't be used by two sessions at the same time. So if two people load the page at the same time it could happen that the file content is deleted. And because of that, I say database.

If you still want to use textfiles use $text = file_get_contents("file.txt"); to read it to variable. And file_put_contents to save to it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM