Recently, I finished a project with the following features:
- It is a SaaS (Software as a Service).
- It is for general purpose: different data resources can be applied with the same PHP codes — ‘reuseable‘.
- It is alike a ORM system(Object-relational mapping):
the mapping of PHP codes and Database Structure are controlled by plain text configure files.
- It is a MVC structure. for ‘V’: using Smarty templates.
- jQuery supports: all AJAX features, plus jQuery 3rd plugins.
For the View, using jQuery plus Smarty templates, it is a high efficient and reasonable solution.
- Whole LCRUD features:
List/sorting/pagination, create, update, view/edit, delete, generate csv/pdf/xml reports, etc.
- Easy to configure:
For new data sources, the only step to make it work is to add entries in a configure file. So all the work is to edit this simple configure file.
- Quick implementation:
e.g., for a new data resources (MySQL table, csv file, XML file etc), it takes only 5-10 minutes to do configure; then all the features are applied.
Due to the reasons of time deadline and specific requests, I did it by PHP OOP, not existing framework. It is pretty cool, very powerful and high performance; the ability of ‘reuse’ are amazing.
I did the ORM (Object-relational mapping ) by myself, not assistance of library, framework or tools. I google some framework such as doctrine which needs long-time learning curve that I can’t afford.
Now it is time to lookback and do some summary. I will list some materials regarding on PHP ORM.
What is ORM (Object/Relational Mapping)?
According to wiki, Object-relational mapping (ORM, O/RM, and O/R mapping) in computer software is a programming technique for converting data between incompatible type systems in object-oriented programming languages. This creates, in effect, a “virtual object database” that can be used from within the programming language. There are both free and commercial packages available that perform object-relational mapping, although some programmers opt to create their own ORM tools.
About Relational Persistence, I get the following info from Java famous Hiberate:
Hibernate is concerned with helping your application to achieve persistence. So what is persistence? Persistence simply means that we would like our application’s data to outlive the applications process. In Java terms, we would like the state of (some of) our objects to live beyond the scope of the JVM so that the same state is available later.
- Relational Databases
Specifically, Hibernate is concerned with data persistence as it applies to relational databases (RDBMS). In the world of Object-Oriented applications, there is often a discussion about using an object database (ODBMS) as opposed to a RDBMS. We are not going to explore that discussion here. Suffice it to say that RDBMS remain a very popular persistence mechanism and will so for the foreseeable future.
- The Object-Relational Impedence Mismatch
‘Object-Relational Impedence Mismatch’ (sometimes called the ‘paradigm mismatch’) is just a fancy way of saying that object models and relational models do not work very well together. RDBMSs represent data in a tabular format (a spreadsheet is a good visualization for those not familiar with RDBMSs), whereas object-oriented languages, such as Java, represent it as an interconnected graph of objects. Loading and storing graphs of objects using a tabular relational database exposes us to 5 mismatch problems…
Sometimes you will have an object model which has more classes than the number of corresponding tables in the database (we says the object model is more granular than the relational model). Take for example the notion of an Address…
- Subtypes (inheritance)
Inheritance is a natural paradigm in object-oriented programming languages. However, RDBMSs do not define anything similar on the whole (yes some databases do have subtype support but it is completely non-standardized)…
A RDBMS defines exactly one notion of ‘sameness’: the primary key. Java, however, defines both object identity (a==b) and object equality (a.equals(b)).
Associations are represented as unidirectional references in Object Oriented languages whereas RDBMSs use the notion of foreign keys. If you need bidirectional relationships in Java, you must define the association twice.
Likewise, you cannot determine the multiplicity of a relationship by looking at the object domain model.
- Data navigation
The way you access data in Java is fundamentally different than the way you do it in a relational database. In Java, you navigate from one association to an other walking the object network.
This is not an efficient way of retrieving data from a relational database. You typically want to minimize the number of SQL queries and thus load several entities via JOINs and select the targeted entities before you start walking the object network.
Why PHP ORM?
ORM is a very good choice for ‘SaaS‘ which is a general, uniform software to use different data resources, to cater different requirements with same software. We don’t need to hardcode any coding when import new data sources, this will make it attractive to extend, explore, admin, mantain many apps with same codes. It makes things simple, clean, and save lots of codes.