好的 PHP ORM 库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/108699/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Good PHP ORM Library?
提问by sgibbons
Is there a good object-relational-mapping library for PHP?
是否有一个很好的 PHP 对象关系映射库?
I know of PDO/ADO, but they seem to only provide abstraction of differences between database vendors not an actual mapping between the domain model and the relational model. I'm looking for a PHP library that functions similarly to the way Hibernatedoes for Java and NHibernate does for .NET.
我知道PDO/ADO,但它们似乎只提供数据库供应商之间差异的抽象,而不是域模型和关系模型之间的实际映射。我正在寻找一个 PHP 库,其功能类似于Hibernate为 Java 所做的方式和 NHibernate 为 .NET 所做的方式。
回答by Ian P
Look into Doctrine.
研究教义。
Doctrine 1.2implements Active Record. Doctrine 2+is a DataMapper ORM.
Doctrine 1.2实现了 Active Record。Doctrine 2+是一个 DataMapper ORM。
Also, check out Xyster. It's based on the Data Mapper pattern.
另外,请查看Xyster。它基于数据映射器模式。
Also, take a look at DataMapper vs. Active Record.
回答by Ian P
Try RedBean, its requires:
尝试RedBean,它需要:
- No configuration
- No database (it creates everything on the fly)
- No models
- etc.
- 无配置
- 没有数据库(它即时创建所有内容)
- 没有模型
- 等等。
It even does all the locking and transactions for you and monitors performance in the background. (Heck! it even does garbage collection....) Best of all... you don't have to write a single... line of code... Jesus this, ORM layer, saved me ass!
它甚至会为您完成所有锁定和事务,并在后台监控性能。(哎呀!它甚至没有垃圾回收....)最重要的是......你没有写任何代码... ...线耶稣这样,ORM层,救了我的屁股!
回答by Ilya Kochetov
回答by bcosca
Axon ORM is part of the Fat-Free Framework- it features an on-the-fly mapper. No code generators. No stupid XML/YAMLconfiguration files. It reads the database schema directly from the backend, so in most CRUDoperations you don't even have to extend a base model. It works with all major PDO-supported database engines: MySQL, SQLite, SQL Server/Sybase, Oracle, PostgreSQL, etc.
Axon ORM 是Fat-Free 框架的一部分- 它具有动态映射器。没有代码生成器。没有愚蠢的 XML/ YAML配置文件。它直接从后端读取数据库模式,因此在大多数CRUD操作中,您甚至不必扩展基本模型。它适用于所有主要的PDO支持的数据库引擎:MySQL、SQLite、SQL Server/Sybase、 Oracle、PostgreSQL等。
/* SQL */
CREATE TABLE products (
product_id INTEGER,
description VARCHAR(128),
PRIMARY KEY (product_id)
);
/* PHP */
// Create
$product=new Axon('products'); // Automatically reads the above schema
$product->product_id=123;
$product->description='Sofa bed';
$product->save(); // ORM knows it's a new record
// Retrieve
$product->load('product_id=123');
echo $product->description;
// Update
$product->description='A better sofa bed';
$product->save(); // ORM knows it's an existing record
// Delete
$product->erase();
Most of all, the plug-in and accompanying SQL data access layer are just as lightweight as the framework: 14 KB (Axon) + 6 KB (SQLdb). Fat-Free is just 55 KB.
最重要的是,插件和随附的 SQL 数据访问层与框架一样轻巧:14 KB (Axon) + 6 KB (SQLdb)。无脂肪只有 55 KB。
回答by SchizoDuckie
I've been developing Pork.dbObject on my own. (A simple PHP ORM and Active Record implementation) The main reason is that I find most ORMs too heavy.
我一直在自己开发 Pork.dbObject。(一个简单的 PHP ORM 和 Active Record 实现)主要原因是我发现大多数 ORM 太重了。
The main thought of Pork.dbObejct is to be light-weight and simple to set up. No bunch of XML files, just one function call in the constructor to bind it, and an addRelation or addCustomRelation to define a relation to another dbObject.
Pork.dbObejct 的主要思想是轻量级且易于设置。没有一堆 XML 文件,只有在构造函数中调用一个函数来绑定它,以及一个 addRelation 或 addCustomRelation 来定义与另一个 dbObject 的关系。
Give it a look: Pork.dbObject
看一看:Pork.dbObject
回答by Tom Pa?ourek
Try Doctrine2. It's probably the most powerful ORM tool for PHP. I'm mentioning it separately from Doctrine 1, because it's a completely different piece of software. It's been rewritten from scratch, is still in beta phase, but it's usable now and developed.
试试Doctrine2。它可能是 PHP 最强大的 ORM 工具。我将它与 Doctrine 1 分开提及,因为它是一个完全不同的软件。它已经从头开始重写,仍处于测试阶段,但现在可以使用并已开发。
It's a very complex ORM, but well designed. Lot of magic from original Doctrine 1 disappeared. It provides a complete solution, and you can write your own ORM on top of Doctrine2or use just one of its layers.
这是一个非常复杂的 ORM,但设计得很好。原始教义 1 中的许多魔法消失了。它提供了一个完整的解决方案,您可以在 Doctrine2 之上编写自己的 ORM或仅使用其中的一层。
回答by Zak
回答by Alvaro
Check out Outlet ORM. It is simpler than Propel and Doctrine and it works similar to Hibernate, only with more of a PHP feel to it.
查看出口 ORM。它比 Propel 和 Doctrine 更简单,它的工作方式与 Hibernate 类似,只是它更像 PHP。
回答by CMS
回答by VDVLeon
I found ORM related classes in the PHP library Flourish.
我在 PHP 库Flourish 中找到了 ORM 相关的类。

