问题描述
如今似乎有两件事似乎很受欢迎,我想知道使用这样的东西的利弊是什么: http://codeigniter.com/user_guide/database/active_record.html ?
另一件事是ORM(例如学说).使用这些好处是什么?
推荐答案
activerecord是ORMS中常见的模式.学说是使用ActivereCord'ish风格的ORM.
使用学说等工具的一些好处:
- 数据库独立性:该代码应易于移植到不同的DBS.例如,我经常使用sqlite测试并在生产中使用MySQL或Postgre,而无需更改代码.
- 他们减少了您必须编写的代码量:应用程序代码的很大一部分与与数据库进行通信.一个ORM照顾大多数,因此您可以专注于编写实际的应用程序.
当然,他们不会没有缺点:
- 学说很重,因此比使用直sql 要慢.
- orms可能很复杂,为您必须学习的内容增加了一定的重量,并且对于缺乏经验的程序员来说,它们有时很难理解
其他推荐答案
您可以查看这些问题,尽管它们并不完全是特定于PHP:
其他推荐答案
我试图使其保持轻巧且易于理解.甚至附带了自己的基于Mootools的类生成器:)
http://www.schizofreend.nl/pork.dbobbobject/pork.dbobject/ p>
检查一下:)
问题描述
There are two things that seem to be popular nowadays and I was wondering what are the pros and cons of using something like this: http://codeigniter.com/user_guide/database/active_record.html ?
Another thing is ORM (Doctrine for instance). What are the benefits of using these?
推荐答案
ActiveRecord is a pattern common in ORMs. Doctrine is an ORM which uses an ActiveRecord'ish style.
Some benefits of using tools like Doctrine:
- Database independence: The code should be easy to port to different DBs. For example, I often test using SQLite and use MySQL or Postgre in production with no changes in code.
- They reduce the amount of code you have to write: A large part of application code deals with communicating with the database. An ORM takes care of most of that, so you can concentrate on writing the actual app.
Of course, they don't come without disadvantages:
- Doctrine is heavy so it is slower than using straight SQL
- ORMs can be complex, adding some weight to what you have to learn, and they can sometimes be difficult to understand for inexperienced programmers
其他推荐答案
You can take a look at these questions though they're not exactly PHP specific:
其他推荐答案
I tried to keep it light-weight and understandable. Even comes with it's own Mootools based Class Generator :)
http://www.schizofreend.nl/Pork.dbObject/
check it out :)