Lets say I’ve got 50 pages, and I want to write a description for about 30 of them.
The description will be about two paragraphs on each page.
Is it more efficient for my server if I save the descriptions in a MySQL database and then query on each page to see if there is a corresponding description, or is it best if I store them in an array in my PHP file and see if the element exists?
Extra Info:
I would edit the array file manually or the db entry through phpMyAdmin which would both take the same amount of time. Also it would only be me editing them so I don’t have to worry about making a quick edit file.
Do it like this:
Store them in an array, in a sepparate file
data.php, in this form:In the caller script you use it like this:
and then use the $data variable throughout the site, as needed. You could also split the array and use several files based on specific criterias, like “the language”, or “article category” or whatever.
If you do it this way, you can always plug in an editor with a web interface to edit that array and store it back with
file_put_contents('data.php', '<?php return '. var_export($data));, where$datahas got its value after processing aPOSTform, for instance, which was generated from the old value of$data.Really elegant, fast, and maintainable!
As a bonus, write helper functions around those serializations, deserializations, etc, such that if you ever change your mind (because your site grows and you end up with hundreds of such arrays), you only have to reimplement those functions to use a database backend, without ever touching the rest of the codebase.
Code reusability and maintanability at its peak! And you get it up and running immediately, without losing the prospect of making it better in the future, if required.