开发者

How does ORM work when using PDO in PHP?

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 inst开发者_JS百科ance 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?


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:

  • http://en.wikipedia.org/wiki/Active_record_pattern
  • http://www.phpactiverecord.org/guides/quick_start

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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜