tags:

views:

401

answers:

2

I've heard that PDO can do some ORM. Is it a good idea to stick with that or should I consider some alternatives that use PDO to do ORM?

In short, what I want to do: I want to automatically map table fields to instance variables. Getters and Setters are created manually. However, I could also think of making an associative array as ivar and then just assign the record set to that array. The getters/setters then just access that array with the appropriate key. But I wonder how PDO could help here to get that done easier?

+1  A: 

You may find these links useful on ORM and PDO with php:

http://forum.kohanaphp.com/comments.php?DiscussionID=3349

http://my.opera.com/zomg/blog/2007/09/03/orm-in-php-using-propel

Sarfraz
+2  A: 

next to the suggestions made by Ahmed, you can also consider doctrine or the php active record implementation:

doctrine: http://www.doctrine-project.org/

active record:

I usually work with propel or active record (as part of cakePHP). Active record supports your associative array goal.

For Propel you can achive the same by making all (required) classes extend a certain uber class. This is defined in your database schema and then generated into all ORM classes. In your uber class you can make the constructor accept associative arrays... So if this is you main objective use active record or a php framework that implements active record.

jodorovski
oh - while posting my reply, ahmed's answer got accepted..
jodorovski
So phpactiverecord internally uses an associative array and just assigns the record set (result set) to that array? Would be interesting how they map all this to the getters/setters then. Off topic: I tend to accept an answer if I think there'll be no more answer. Better than forgetting accepting any answer :-) I think it doesn't matter if an answer got already accepted. People should still provide answers, if they think this can help further. In this case, I find your answer even more helpful, so I changed the acceptance. Thanks!
openfrog