0

I've designed a web application designed to manage menus on restaurant websites. The application allows the restaurant manager to make changes to the menu without contacting the web designer (me) every time. In the design process, I initially used a data file to store the menu data. The reasoning is because the initial impetus for the project was making it easier for me to make changes to the website content and I wanted to be able to edit the data directly if necessary.

Now that the project has grown into a full-fledged web application, I'm wondering if I should forgo the data files and use a database instead. Because this is for restaurant menus, the amount of data is really small, changes aren't made on a regular basis, and even then, changes would be minor. Would I benefit by changing over to a database? Are there noticeable benefits?

Lee Blake
  • 341
  • 1
  • 2
  • 15

1 Answers1

1

PHP offers some nice functions to store data in files, be it with json_encode() and json_decode(), var_export(), to save variables in native PHP syntax, or with fputcsv() and fgetcsv() to handle files in CSV format.

In smaller projects, I have saved data to files frequently but I would never use my own function over the ones I just mentioned now. They're very convenient and once you know how they act, you can use them everywhere and don't have to re-invent the wheel.

Now, a database is an absolute must when you're dealing with a lot of data or when you could have concurrent modifications. flock() might alleviate the concurrent modifications thing a little bit, but after a certain scale, using a database cannot should not be avoided.

Another advantage databases have to offer is that they use the SQL language, which was designed to deal with data. You can thus whip up some nice statistics (etc.) with a few simple lines, whereas if you're trying to juggle a lot of data in PHP, it can get messy quite fast.

Conclusion: In your specific case, however, I would not suggest switching to a database. As you've said, there isn't much data, it is not being written to frequently and I thus think that the trouble of setting up a database and changing all of your code to equivalent SQL statements is not worth it. Your effort is probably better spent elsewhere.

ljacqu
  • 2,132
  • 1
  • 17
  • 21
  • That was my general conclusion. A question about concurrent access: Because the main web page accesses these same files (read only) to display the menu, could that cause some data integrity issues if someone loads the webpage at the same time someone saves changes? – Lee Blake Aug 29 '14 at 06:33
  • @LeeBlake If the home page only reads from the file, I would say the worst is that the menu could be empty if the visitor is extremely unlucky. Personally, I wouldn't worry about it. There's a very small chance. – ljacqu Aug 29 '14 at 06:35