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

发布于 2024-12-10 19:41:22 字数 1539 浏览 5 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

故事与诗 2024-12-17 19:41:22

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

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

  • MySQL
  • MySQLi(仅限 PHP5)
  • PostgreSQL
  • Oracle
  • Frontbase
  • Interbase/Firebird(仅限 PHP5)
  • MSSQL
  • SQLite

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.

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:

  • MySQL
  • MySQLi (PHP5 only)
  • PostgreSQL
  • Oracle
  • Frontbase
  • Interbase/Firebird (PHP5 only)
  • MSSQL
  • SQLite
冰雪之触 2024-12-17 19:41:22

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

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

经过广泛测试

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

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

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

速度

是的。默认情况下,Zend_Db 使用 PDO。

轻量级

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

Zend有一个广泛的缓存系统

开源许可证

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

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
    }
}

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

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

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

必须阅读的内容 - http://framework.zend.com/manual/en/zend.db.table.html

更多参考此处
查看此关系问题了解更多信息

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

Zend was started by folks who were the core contributors of 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.

speed

Yes. Zend_Db using PDO, by default.

lightweight

Yes

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

Zend has an extensive caching system.

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

More reference here.
Check this relation question for more information

万劫不复 2024-12-17 19:41:22

我对 Propel 有很好的经验。 Doctrine 类似,我听说过它的好消息,但我没有经验。

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

舞袖。长 2024-12-17 19:41:22

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

笔记:
我大约一年前用最新稳定版本的 DBAL 和 php 做了这件事,也许所有这些问题现在都已经解决了。

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 right version 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.

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.

断舍离 2024-12-17 19:41:22

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

它还支持 nosql 数据库,如 mangodb 等...

它有内置的缓存系统,可以提高应用程序的性能。

它还具有扩展支持,如分页、查询生成器等。

以下是 propel 和 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 |

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

查看最后两条记录,学说 2.0 的性能如何提高...

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

It also supports nosql db like mangodb etc...

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.

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

四叶草在未来唯美盛开 2024-12-17 19:41:22

如果您只需要使用 MySQL,使用 PHP 的 MySQL DALMP 数据库抽象层。 可以是与缓存/内存缓存/redis 一起使用的选项

,并且会话处理也非常简单和轻便。

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

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

原来分手还会想你 2024-12-17 19:41:22

Zend_Db 怎么样?对于缓存来说,唯一需要 Zend_Cache 的东西,而轻量级是模糊的东西。我想所有其他要求都符合。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文