迄今为止最好的 PHP DAL(数据抽象层)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7807851/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 03:24:26  来源:igfitidea点击:

Best PHP DAL (data abstraction layer) so far

phpdatabasedatabase-abstraction

提问by sakhunzai

What is the best PHP DAL (data abstraction layer) so far developed under any open source project which we could re-use with good faith?

迄今为止,在任何我们可以真诚地重用的开源项目下开发的最好的 PHP DAL(数据抽象层)是什么?

I am finding it hard to choose a DAL for my application that sufficiently supports abstraction to most common databases systems (MySQL, PostgreSQL, MSSQL, Oracle, etc) and is:

我发现很难为我的应用程序选择一个 DAL,它足以支持对大多数常见数据库系统(MySQL、PostgreSQL、MSSQL、Oracle 等)的抽象,并且是:

  1. widely tested,
  2. has good interface (readable method names, good parameter passing strategy),
  3. fast,
  4. lightweight,
  5. providing cache (e.g integrates with Memcache or supports a good caching mechanism),
  6. open-source license,
  7. should have adapters for at least MySQL/MySQLi (non-PDO based)
  1. 广泛测试,
  2. 具有良好的接口(可读的方法名称,良好的参数传递策略),
  3. 快速地,
  4. 轻的,
  5. 提供缓存(例如与 Memcache 集成或支持良好的缓存机制),
  6. 开源许可证,
  7. 至少应该有适用于 MySQL/MySQLi 的适配器(非基于 PDO)

Some of the libararies to consider:

一些需要考虑的库:

Please don't consider:

请不要考虑:

  • PDO
  • All ORMs (however, Doctrine seems to have a separate DAL besides ORM)
  • PDO
  • 所有 ORM(但是,除了 ORM,Doctrine 似乎还有一个单独的 DAL)

回答by xmarcos

If you can do with PHP 5.3, I would highly recommend Doctrine DAL, it's built on top of PDO, so you get the same performance plus a great API.

如果您可以使用 PHP 5.3,我强烈推荐Doctrine DAL,它建立在 PDO 之上,因此您可以获得相同的性能和出色的 API。

Update:If Doctrine is not good, you can try MDB2. It has drivers for most of the popular RDBMS, a robust API, great docs and a huge user base:

更新:如果 Doctrine 不好,你可以试试MDB2。它具有大多数流行 RDBMS 的驱动程序、强大的 API、出色的文档和庞大的用户群:

  • MySQL
  • MySQLi (PHP5 only)
  • PostgreSQL
  • Oracle
  • Frontbase
  • Interbase/Firebird (PHP5 only)
  • MSSQL
  • SQLite
  • MySQL
  • MySQLi(仅限 PHP5)
  • PostgreSQL
  • 甲骨文
  • 前垒
  • Interbase/Firebird(仅限 PHP5)
  • MSSQL
  • SQLite

回答by Lenin Raj Rajasekaran

I have been using Zend_Db for my web application for the past 1 year. I think, Zend Framework is the best by far.

在过去的 1 年里,我一直在将 Zend_Db 用于我的 Web 应用程序。我认为,Zend Framework 是迄今为止最好的。

Zend was started by folks who were the core contributors of PHP.(1)

Zend 是由 PHP 的核心贡献者创建的。(1)

widely tested

广泛测试

Yes. It is used by thousands of projects and has a active community of developers.

是的。它被数千个项目使用,并且拥有活跃的开发人员社区。

has good interface (readable method names ,good parameter passing strategy)

具有良好的接口(可读的方法名称,良好的参数传递策略)

Yes. All Components can be easily customized to your needs. Every component in Zend is loosely coupled, meaning you can use any component without any dependency on any other component in the framework.

是的。所有组件都可以根据您的需要轻松定制。Zend 中的每个组件都是松散耦合的,这意味着您可以使用任何组件,而不依赖于框架中的任何其他组件。

speed

速度

Yes. Zend_Db using PDO, by default.

是的。Zend_Db 默认使用 PDO。

lightweight

轻的

Yes

是的

providing cache (e.g integrates with memcache or supports a good caching mechanism)

提供缓存(例如与 memcache 集成或支持良好的缓存机制)

Zend has an extensive caching system.

Zend 有一个广泛的缓存系统

open-source license

开源许可证

Yes

是的

To access a DB table, all you have to do, is create a class for it by setting the table name and its primary key as its fields.

要访问一个数据库表,您所要做的就是通过将表名和它的主键设置为它的字段来为它创建一个类。

class User extends Zend_Db_Table {

    protected $_name = "users";  //tablename
    protected $_primary = "user_key"; //primary key column

    function addNewUser($name,$age,$email) {
          //Validate input and add Logic to add a new user
          //Methods are available to insert data like $this->insert($data)
          // where $data is an array of column names and values
          // Check links below for documentation
    }
}

This is called a model. In this class, you can create all the methods related to 'User' entity like adding a new user, editing user etc.

这称为模型。在这个类中,您可以创建与“用户”实体相关的所有方法,例如添加新用户、编辑用户等。

In your application code, you can use this as,

在您的应用程序代码中,您可以将其用作,

$u = new User();
$u->addNewUser('Name','Age','email');

Must Read this - http://framework.zend.com/manual/en/zend.db.table.html

必须阅读这个 - http://framework.zend.com/manual/en/zend.db.table.html

More reference here. Check this relation questionfor more information

更多参考这里。检查此关系问题以获取更多信息

回答by nimmen

I had some trouble with doctrine DBAL, mostly with the schema/database/table creation, it was buggy and some of documentation was different from actual interfaces and class methods(I did read rightversion documentation), I had to use raw sql statements for some of those things.
Everything else seemed to be fine, it was small project so I did not use all the features doctrine DBAL provides.

我在学说 DBAL 方面遇到了一些麻烦,主要是模式/数据库/表的创建,它有问题,并且一些文档与实际接口和类方法不同(我确实阅读了正确版本的文档),我不得不使用原始 sql 语句其中一些东西。
其他一切似乎都很好,这是一个小项目,所以我没有使用 DBAL 提供的所有功能。

Note: I did it around a year ago with latest stable version of doctrine DBAL and php, maybe all those problems are fixed by now.

注意:我大约在一年前使用最新的稳定版 Dotct DBAL 和 php 完成了这项工作,也许所有这些问题现在都已解决。

回答by Prashanth Pratapagiri

Doctrine 2.0 is the best one in the market because it is supported by topmost frameworks like Zend framework, Symfony.

Doctrine 2.0 是市场上最好的,因为它得到了 Zend 框架、Symfony 等顶级框架的支持。

It also supports nosql db like mangodb etc...

它还支持 nosql db,如 mangodb 等...

It has inbuilt cache system which can boost the application.

它具有内置的缓存系统,可以提升应用程序。

It is also having Extension support like pagination, query builder etc

它还具有扩展支持,如分页、查询构建器等

Here are some of the bechmarks results of propel and doctrine

以下是推进和学说的一些基准结果

                               | Insert | findPk | complex| hydrate|  with  |
                               |--------|--------|--------|--------|--------|
                  PDOTestSuite |    132 |    149 |    112 |    107 |    109 |
             Propel14TestSuite |    953 |    436 |    133 |    270 |    280 |
        Propel15aLa14TestSuite |    926 |    428 |    143 |    264 |    282 |
             Propel15TestSuite |    923 |    558 |    171 |    356 |    385 |
    Propel15WithCacheTestSuite |    932 |    463 |    189 |    342 |    327 |
           Doctrine12TestSuite |   1673 |   2661 |    449 |   1710 |   1832 |
  Doctrine12WithCacheTestSuite |   1903 |   1179 |    550 |    957 |    722 |
            Doctrine2TestSuite |    165 |    426 |    412 |   1048 |   1042 |
   Doctrine2WithCacheTestSuite |    176 |    423 |    148 |    606 |    383 |

These are the key observations for the Doctrine 2 results.

这些是 Doctrine 2 结果的关键观察结果。

see the last two records how the performance has increased with doctrine 2.0...

请参阅最后两个记录,性能如何随着学说 2.0 的增加而增加...

回答by nbari

If you only need to work with MySQL, DALMP Database Abstraction Layer for MySQL using PHP.can be an option

如果您只需要使用 MySQL,DALMP Database Abstraction Layer for MySQL using PHP。可以是一个选择

works with cache/memcache/redis and also does session handling very simple and light.

与 cache/memcache/redis 一起工作,并且会话处理也非常简单和轻便。

回答by Jorrit Schippers

I have good experience with Propel. Doctrineis similar, I heard good things about it but I don't have experience.

我对Propel有很好的经验。教义是相似的,我听说过有关它的好消息,但我没有经验。

回答by Dmytro Zavalkin

What about Zend_Db? The only thing that for caching you need Zend_Cache, and lightweight is vague thing. All other requirements are matched I guess.

什么Zend_Db的?缓存需要 Zend_Cache 的唯一东西,而轻量级是模糊的东西。我猜所有其他要求都匹配。