PHP中的ORM和活动记录模式? [英] ORM and Active Record Pattern in PHP?

查看:143
本文介绍了PHP中的ORM和活动记录模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在有两件事似乎很受欢迎,我想知道使用这样的东西有哪些优点和缺点: http://codeigniter.com/user_guide/database/active_record.html



另一件事是ORM(例如Doctrine )。使用这些的好处是什么?

解决方案

ActiveRecord是ORM中常见的一种模式。 Doctrine是使用ActiveRecordyish风格的ORM。



使用诸如Doctrine之类的工具的一些好处:




  • 数据库独立性:代码应该很容易地移植到不同的数据库。例如,我经常使用SQLite进行测试,并在生产中使用MySQL或Postgre,而不会改变代码。

  • 它们减少了必须编写的代码量:大部分应用程序代码交易与数据库进行通信。一个ORM负责大部分的工作,所以你可以集中精力编写实际的应用程序。



当然,他们不来没有缺点:




  • 教义很重,所以比使用直SQL更慢[/ li>
  • ORM可以复杂的,增加了你必须学习的一些重量,有时候对于没有经验的程序员来说,他们有时可能难以理解。


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

这篇关于PHP中的ORM和活动记录模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆