Web Hosting Talk







View Full Version : PHP and ORM


dmxo
05-09-2006, 03:37 AM
Maybe this article may help out some PHP Developers:
Maybe Zuraski and the folks leading PHP are going the right way as I felt from the Paris Meeting (review my post about PHP 6), but I think we -PHP developers, should start reading more about how to code the right way using the right tools.
ORM or Object-relational mapping, is a topic I recently went through after a discussion with a experienced developer, ORM is aimed towards setting you free from DB with all the issues related to, such as DB design and Normalization, ERD creation and updating, etc..
ORM is a set of classes that allows you to create classes that you, whenever needed, instantiate obejcts from then do your full CRUD (create, review, update and delete) in the object level, which will automatically reflect on DB.
Certainly we need to show some code:
-------------------
The full article is here:
http://www.owahab.com/?q=node/9

innova
05-10-2006, 05:30 PM
ORM is aimed towards setting you free from DB with all the issues related to, such as DB design and Normalization

If you think this is true you dont understand the purpose of ORM.

ORM does not relieve you of the need to properly create your databases and provide for normalization.

ORM in a nutshell is simply another way to access your database data, by accessing it through objects rather than using SQL.

ORM is quite handy for single-table updates and inserting or editing single-table data. However, overuse/misuse of ORM can be tons more inefficient than simply using RAW sql alone.

For example (I believe the ADODB active record docs mention this), increasing the price of every item in a table of products.

ORM example (from adodb docs):
$recs = $db->GetActiveRecords("Products","category='Furniture'");
foreach($recs as $rec) {
$rec->price *= 1.1; // increase price by 10% for all Furniture products
$rec->save();
}


SQL Example:
$db->Execute("update Products set price = price * 1.1 where category='Furniture'");


As you can see, its not the cure-all or a magic solution... when you are dealing with row-level data, it can make it easier to work with than writing a ton of SQL queries. Hope that helps clear things up a bit.