問題描述
現在有兩件事似乎很流行,我想知道使用這樣的東西的利弊是什么:http://codeigniter.com/user_guide/database/active_record.html ?
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 ?
另一件事是 ORM(例如 Doctrine).使用這些有什么好處?
Another thing is ORM (Doctrine for instance). What are the benefits of using these?
推薦答案
ActiveRecord 是 ORM 中常見的一種模式.Doctrine 是一個使用 ActiveRecord 風格的 ORM.
ActiveRecord is a pattern common in ORMs. Doctrine is an ORM which uses an ActiveRecord'ish style.
使用 Doctrine 等工具的一些好處:
Some benefits of using tools like Doctrine:
- 數據庫獨立性:代碼應該很容易移植到不同的數據庫.例如,我經常使用 SQLite 進行測試,并在生產中使用 MySQL 或 Postgre,而無需更改代碼.
- 它們減少了您必須編寫的代碼量:應用程序代碼的很大一部分處理與數據庫的通信.ORM 負責處理大部分工作,因此您可以專注于編寫實際應用.
當然,它們并非沒有缺點:
Of course, they don't come without disadvantages:
- Doctrine 很重,所以它比使用直接 SQL 慢
- ORM 可能很復雜,增加了您必須學習的內容的負擔,而且有時對于沒有經驗的程序員來說可能難以理解
這篇關于PHP 中的 ORM 和 Active Record 模式?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!