|Classes of Sergey Beskorovayniy||>||Silex MVC Blog||>||library/AR/README.md||>||Download|
PHP ActiveRecord - Version 1.0
A brief summarization of what ActiveRecord is:
> Active record is an approach to access data in a database. A database table or view is wrapped into a class, > thus an object instance is tied to a single row in the table. After creation of an object, a new row is added to > the table upon save. Any object loaded gets its information from the database; when an object is updated, the > corresponding row in the table is also updated. The wrapper class implements accessor methods or properties for > each column in the table or view.
More details can be found here.
This implementation is inspired and thus borrows heavily from Ruby on Rails' ActiveRecord. We have tried to maintain their conventions while deviating mainly because of convenience or necessity. Of course, there are some differences which will be obvious to the user if they are familiar with rails.
Setup is very easy and straight-forward. There are essentially only three configuration points you must concern yourself with:
Alternatively (w/o the 5.3 closure):
PHP ActiveRecord will default to use your development database. For testing or production, you simply set the default connection according to your current environment ('test' or 'production'):
Once you have configured these three settings you are done. ActiveRecord takes care of the rest for you. It does not require that you map your table schema to yaml/xml files. It will query the database for this information and cache it so that it does not make multiple calls to the database for a single schema.
These are your basic methods to find and retrieve records from your database. See the Finders section for more details.
Here we create a new post by instantiating a new object and then invoking the save() method.
To update you would just need to find a record first and then change one of its attributes. It keeps an array of attributes that are "dirty" (that have been modified) and so our sql will only update the fields modified.
Deleting a record will not destroy the object. This means that it will call sql to delete the record in your database but you can still use the object if you need to.
Please refer to CONTRIBUTING.md for information on how to contribute to PHP ActiveRecord.