Libdatabase
|
#Libdatabase
This is a simple ORM database mapper which delivers some convenience methods to query, create and update objects. It does not support associations. Instead I use the convention that a foreign key is the name of the table appended '_uid'. The only other convention is that an object must have a property named 'uid' and when you call save and the uid == 0 it will be converted to an insert statement otherwise it will be converted to an update statement.
This library uses php PDO library.
Below is defined a Sample class
This class will have a corresponding table name sample where properties are columns.
As you se the properties are describe by types, which means that when the object is loaded from a table row, the columns are converted to the property type. In that way the date is not a string, but an date object with meaningful operation.
To create an object and persist it
To to find one or more objects
To change a property and persist it
To delete an object
You also have access to the lower level database function in the DB class, which provides transformations for DbObject to sql or you can write the sql your self.
This library uses the Config class from libutil, where you can put in the database configuration into the ini file:
The section name corresponds to the static property $db in the DbObject class. The default name is 'defaultDb'.