I created my Stash classes and functions as an easy way to stash object data.
The classes were designed with multiple methods of storing data in mind, so that storing data to an XML file would be no more complicated to a developer than storing in a DB, and use the same method calls.
I have made the classes available to the public, including the code to store to a MySQL database. I wrote the code to store to a couple of other formats (XML, YAML) but as these were used in commercial products I unfortunately cannot make them open source.
I eventually abandoned further development of these classes as I generally use Doctrine ORM, however these classes are lightweight and suitable for small projects or those where performance is important.
The classes comprise of three parts:
- SQL query builder
- Bean class for individual objects
- Collection class that works with collections of objects
The query builder makes creating queries easy. Parts of the query can be specified in any order, and are specified using methods, like this:
$query = new sql_query()
->where("or last_name='$last_name' ")
// only get admin users?
$row = $query->fetchRow();
The stash bean has several useful methods, such as retrieve(), save(), update() etc. which interact with the DB (or other storage mechanism)
By default the class generates UUIDs for object ids. You can change this by overloading the create_id() method. (e.g. make create_id() return null if you are using an auto-incrementing integer)
A useful feature of the bean is archiving.
// store a copy of the document with the current date
// fetch the archived version of the doc from a specific date
The collection class allows you to work with a collection of objects. For example, fetching documents created in a specific time:
$documents = new Documents;
$documents->where("date_created > '2010-01-01 00:00:00'");
foreach($documents->collection() as $document)
You can download the classes, with an example of how to use them, here
Full API documentation for the stash classes is available in the API Docs