Data storage should always be considered on the front-end of a project... not the end.
A database system might be preferable if there is a lot of data which must be stored and queried often. Sometimes for small datasets a flat file or even a memory caching system (such as memcache or APC) is the best course of action. It really all depends.
For small datasets, I have saved a serialize array to a flat file (and memecache) in which my keys were the index that I was looking for. Yes there can be some overhead, but it has worked pretty good in certain cases.
To save file:
Code:
$a = array();
$a['blah'] = 23;
$a['blah 123'] = 1234;
$a['blahblahblah'] = 33;
$z = file_put_contents('myfile.txt', serialize($a));
To review value of 'blah'
Code:
$a = unserialize(file_get_contents('myfile.txt'));
echo $a['blah'];
I am more a fan of using this technique with memory based caching but it would work with flat files too.
|