(Don't believe this is a "best practice" question as I believe there will be a single better choice).

I need to choose a data storage option to store specific site data to allow easy management and re-usability: array; class; DB; Other; but am not sure which one would be adequate.

The data in question is my Services, which is a list of titles and descriptions.

Example of the text:

On-site SEO
We provide On and Off site SEO, by careful keyword assignment and placement, blah etc, etc blah etc, etc blah etc, etc blah etc, etc blah etc, etc.

Logo Design
We can provide clean and elegant logos suited to your current company branding... blah etc, etc blah etc, etc blah etc, etc blah etc, etc blah etc, etc blah etc, etc blah etc, etc blah etc, etc blah etc, etc blah etc, etc.

Each title is no more than 5 words, and descriptions are about 70 words/350 chars, and I have about 20 titles and descriptions.

As services can be changed, retracted, and new added, I want control over the data - more than just editing a view/template file where the raw output/HTML is done, because I:

  1. Require the data to be reusable on different templates
  2. Want the option to use only a part of each data, eg just the title(s) so a specific array index, or class method, DB table row, etc

I'm reluctant use an array, given the size of the Description text and number of services (20). And it might end up fiddly accessing a specific array value, having to know the exact key (the title), and the key being long.
I could use a multidimensional array, with the top level key being a simple reference, but it seems well overkill for the requirements.

It seems a waste of a class as the data itself is static, and feel I'd be abusing the point of OOP a bit.

I could use a DB, but the site doesn't require a DB for anything else currently, though am happy to implement one if worthwhile for this.

The site is on a framework, loosely on MVC/P, so can implement anything easily.

So, out of the options: array; class; database; (other?) which would be the most suitable for this scenario?

The overhead difference is not an issue, as it'll be marginal enough between all three for my requirements (small site, good hosting etc).

Access to said data will only be on a couple of pages, so having it in memory isn't a large requirement (AFAIK).

  • This question isnt very clear regarding the scope/scale of what you are doing. Is this just a few items for your personal site? If you want to re-use them on different pages, stick them in variables in a PHP file and require() it whereever you want them to be available. Feb 20, 2014 at 19:44
  • @GrandmasterB Variables wouldn't be suited for this. There's 40 items as I have two data requirements - the title and description. And I'd have to pair up variables too for title/description. Besides something as old hat and clunky as "Sticking them in variables in a PHP file and requiring them when needed" ruins the framework setup I have
    – James
    Feb 20, 2014 at 21:24
  • Thats why you need to provide specifics about scope and scale, so that people answering the question can advise towards what is suitable. Feb 20, 2014 at 21:32

1 Answer 1


Based on what you've defined - you want something thats more than variables in an included() file, but less than a database server - I'd look at keeping the information in an SQLite database. Thats a single file, server-less database system. I believe its built into PHP, so you wouldn't have to install anything. And then if you ever need to scale up to something like MySQL, it shouldn't require many changes.

  • Thanks for trying to help. Sorry if I gave too little info, I thought I provided enough to get the message across. Wouldn't SQLite be more work to implement and maintain than an array? I'll use it, if that is the best option for the scenario. But I'll also use an array IF it's the better option. Rather than just SQLite just because it's middle of the road of DB and array. I just wanted some pro input as to what the best approach would be for this, especially as I want re-usability.
    – James
    Feb 20, 2014 at 23:38
  • An array is what you might use when the PHP page is loading. But how do you get that data into an array in the first place? It's got to be stored someplace and retrieved. Feb 20, 2014 at 23:49
  • Well, the array would be stored in a file in view/Template (or Model) - tmpl_SiteServicesArray.php or whatever. Whatever I do it has to be stored somewhere. Either file or database. But in case of my asking about a class versus an array, both need a file to store the array and data, so that is moot point really. If a DB approach would be wiser for this scenario, then I'd also need a file in Model to get the data from DB. But after there, still, is a simple array or class better?
    – James
    Feb 21, 2014 at 0:45
  • Isn't putting it in a php file what I suggested originally in the comments? Feb 21, 2014 at 3:38
  • Whatever I do, I need either a file or database. My question is not about whether I need to use a file, it's about whether I should put this data in an array, class, store in a database or other. A class or array obviously need a file. A database solution needs a file too, in Model, to get the data. So let's say I need a file, in that file, your suggestion of variables doesn't sound great. So would it be better in an array or class given it's overkill for both, or would a database be better? Or is there something else?
    – James
    Feb 21, 2014 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.