An ORM based on PDO written years ago
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
IDEAS :
- add triggers on relations for the other member of the relation (default: keep) :
- ondelete="(keep|delete)" done
- onupdate="(keep|update)"
- use camelizer and pluralizer classes to compute missing table or field names
- DatabaseToSchema class to convert an existing database table to a PDOMapperSchema
DRAFT - WORKING COPY !!!!
This document describes a simple ORM implementation based on PHP Data Object.
@version 1.0 2012-08-31
@copyright 2001-2012 Universite catholique de Louvain (UCL)
@author Frederic Minne <zefredz@claroline.net>
@license http://creativecommons.org/licenses/by-nc-sa/2.0/be/ CreativeCommons Attribution-Noncommercial-Share Alike 2.0
Retreiving data from a database always uses similar SQL queries or PHP code. Abstraction layers are good the provide helpers to easily get data from the database but they do not reduce the amount of code needed for the queries themselves.
Most of this code could be generated automaticaly and let the developpers focus on more important issues such as security, application architecture...
Automatic SQL queries generation could lead to more security since the verification and filtering of the data passed to and retreived from the database can be included in the automatic generation process (PDO is really great at this).
Another advantage is that the SQL code is contained into one single class. So bugs and security flaws are easier to find and correct.
The ORM architecture described here is aimed to provide the following features :
- a lightweight easy to use and understand object-oriented ORM architecture
- based on PDO, simplexml and other PHP 5 powerfull features
- CRUD (Create Read Update Delete) objects based on PHP classes with no need to implement the SQL queries
- basic relations :
1. hasone : object has another object mapped from the db mapped to one of his attribute
2. hasmany : object has many objects mapped from the db mapped to one of his attribute
- PDO: PHP Data Object
- ORM: Object-Relationnal Mapper
- DSN: Data Source Name
- CRUD: Create Read Update Delete
code source are in courier new
At this time the basic operations select(One/All), create, update, delete, hasOne and hasMany are already working. Planned feature : hasAndBelongsToOne/Many based on a n:m relation table.
Note that the database and the tables used by the PDO-based ORM must exist in the DBMS.