Home » PHP » Relational v/s Object Sql Model in PHP

Relational v/s Object Sql Model in PHP

Im confusing about using relational or object model for database in programming languages. while relational model is tradional, simpler, fast and easy. But It is very bad practice for frameworks where good coding standards are requirement. Object Model is good in this case but it make developer life more complex. and most of object model also lack of completeness for all sql statements in general. One example is UNION statment which is not an easy in Object Model to implement. and Also performing subquery using OM is also a big challenge.

Let see an example For Sql Query

Relational Model :

$q = “SELECT id, name FROM tbl_test WHERE id=1”;
$query = mysql_query($q);
$row = mysql_fetch_row($query);

Relational Model :(Using Symfony Framework)

$c = new Criteria();

$c->addSelectColumn(TestPeer::ID);
$c->addSelectColumn(TestPeer::NAME);
$c->add(TestPeer::ID, 1);

$RS = TestPeer::doSelectRS($c);
Now you can see the elegantness but complexity of OM.

Advertisements

One thought on “Relational v/s Object Sql Model in PHP

  1. After a long gap write my first Blog, Now I see the my blog again. Even today I am on same front Object or Relational. Biggest challenge in Propel ORM (used in symfony) is to handle complaex queries. If we have a subquery in select pharse then only option for us write as a simple query and add as column Ex.
    $c->addAsColumn(’group_name’, ‘(SELECT group.group_name FROM group WHERE group.id=group_id)’);
    Now this solution end the purpose of using ORM.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s