简体   繁体   English

什么时候应该使用doctrine ORM和zend-db-table?

[英]When should use doctrine ORM and when zend-db-table?

在项目规模,学说与zend-db-table速度和性能方面,何时应该在Zend项目中使用doctrine,以及什么时候使用zend-db-table?

Any ORM framework gives you benefit for development productivity, not runtime efficiency. 任何ORM框架都可以提高开发效率,而不是运行时效率。 Doctrine is no different from Zend_Db_Table in this regard. 在这方面,Doctrine与Zend_Db_Table没有什么不同。

If you are choosing between Doctrine and Zend_Db_Table, choose based on the features that make it easier or faster to write the code. 如果您在Doctrine和Zend_Db_Table之间进行选择,请根据使编写代码更容易或更快的功能进行选择。

No ORM framework can automatically make database queries faster in the general case. 在一般情况下,没有ORM框架可以自动更快地进行数据库查询。 If you need high-performance database queries, you should learn to code SQL queries, and design your schema and indexes to support performance given the queries you need to run. 如果需要高性能数据库查询,则应学习编写SQL查询代码,并设计模式和索引以根据需要运行的查询来支持性能。

Use whatever you are most comfortable with and will make you the most efficient. 使用您最满意的任何东西,将使您最有效。 You and your fellow developers are probably the most expensive resource, and it's probably cheaper to buy additional hardware, if needed, than you having to worry about possible future performance considerations. 您和您的开发人员可能是最昂贵的资源,如果需要,购买额外硬件可能比您不必担心未来可能的性能考虑因素更便宜。

Of course, you will still need to perform basic database optimizations such as creating sensible indexes etc. But I feel that those "optimizations" go without saying. 当然,您仍然需要执行基本的数据库优化,例如创建合理的索引等。但我觉得那些“优化”不言而喻。

if you have a lot of SQL queries, and lack of knowledge (knowing nothing about caching or query optimization, etc.) and lack of time use Zend_DB it is faster and easier to be understood and it is good enough for YOU - the one who is in lack of knowledge and time and want to be as fast as possible. 如果你有很多SQL查询,缺乏知识(对缓存或查询优化一无所知等)并且缺乏时间使用Zend_DB它更快更容易理解,对你来说已经足够了 - 那个人缺乏知识和时间,希望尽可能快。

but if you wanna a killer ORM doctrine wins. 但如果你想要一个杀手ORM主义获胜。 but it requires more time and energy to be used efficiently. 但它需要更多的时间和精力才能有效地使用。

and if you wanna be a DB killer, we're gonna go off topic. 如果你想成为一名数据库杀手,我们就会脱离主题。 it is different. 他们有区别。 and it is not necessarily based on what tools you use. 它不一定基于您使用的工具。 (some DB killers probably use PDO itself and their own models, who knows?) (一些DB杀手可能会使用PDO本身和他们自己的模型,谁知道?)

Doctrine helps you define a better business logic and ORM, but it is an absolute performance killer in term of memory and CPU. Doctrine可以帮助您定义更好的业务逻辑和ORM,但就内存和CPU而言,它是绝对的性能杀手。 Zend table gateway is 5x times faster than Doctrine. Zend表网关比Doctrine快5倍。 And you can extend Zend table gateway to remove some data type parser and that will give you an improvement of 5x more preserving still the benefit of and simple ORM. 并且您可以扩展Zend表网关以删除一些数据类型解析器,这将使您的性能提高5倍,同时保留了简单的ORM的优点。 Here is my FastTablegateway class: 这是我的FastTablegateway类:

<?php
namespace Application\Libraries;

use Zend\Db\TableGateway\TableGateway;
use Zend\Db\Adapter\AdapterInterface;
use Zend\Db\ResultSet\ResultSetInterface;
use Zend\Db\Sql\Select;
use Zend\Db\Sql\Sql;

class FastTablegateway extends TableGateway{

    protected $mysqli_adapter = null;

    /**
     * Constructor
     *
     * @param string $table
     * @param AdapterInterface $adapter
     * @param Feature\AbstractFeature|Feature\FeatureSet|Feature\AbstractFeature[] $features
     * @param ResultSetInterface $resultSetPrototype
     * @param Sql $sql
     * @throws Exception\InvalidArgumentException
     */
    public function __construct($table, AdapterInterface $adapter, $features = null, ResultSetInterface $resultSetPrototype = null, Sql $sql = null, $mysqli = null)
    {
        $this->mysqli_adapter = $mysqli;
        parent::__construct($table, $adapter, $features, $resultSetPrototype, $sql);
    }


    protected function executeSelect(Select $select)
    {
        $time = time();
        $selectState = $select->getRawState();
        if ($selectState['table'] != $this->table) {
            throw new \Exception\RuntimeException('The table name of the provided select object must match that of the table');
        }

        if ($selectState['columns'] == array(Select::SQL_STAR)
        && $this->columns !== array()) {
            $select->columns($this->columns);
        }

        //apply preSelect features
        $this->featureSet->apply('preSelect', array($select));

        if(!$this->mysqli_adapter){
            // prepare and execute
            $statement = $this->sql->prepareStatementForSqlObject($select);
            $result = $statement->execute();
        }else{
            $q = $this->sql->getSqlStringForSqlObject($select);
            //var_dump($q);
            $result = $this->mysqli_adapter->query($q);
            $result = is_object($result) ? $result->fetch_all(MYSQLI_ASSOC) : [] ;
        }

        // build result set
        $resultSet = clone $this->resultSetPrototype;
        //var_dump(is_object($result) ? $result->num_rows : 'A');
        $resultSet->initialize($result);

        // apply postSelect features
        //$this->featureSet->apply('postSelect', array($statement, $result, $resultSet));

        return $resultSet;
    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Zend Framework中使用Doctrine ORM时发生致命错误 - Fatal Error when using Doctrine ORM with Zend Framework 在使用Doctrine 2和Zend Framework时,应该在哪里放置业务逻辑 - Where should the business logic be placed when using Doctrine 2 and Zend Framework ORM / Doctrine2-何时保留? - ORM/Doctrine2 - When to persist? 使用Doctrine ORM&Zend2&Oracle保存日期时,“文字与格式字符串不匹配” - “literal does not match format string” when saving dates using Doctrine ORM & Zend2 & Oracle Zend / Doctrine无法执行ORM操作,该表已存在 - Zend/Doctrine can't perform ORM operations, table already exists Zend 2中的Zend Db(标准或表网关)与Doctrine-优点/缺点 - Zend Db (standard or table gateway) vs Doctrine in Zend 2 - Pros/Cons Zend db-什么时候应该引用以避免sql注入? - Zend db - When should I quote to avoid sql injection? Zend_db只在我的主模块中出错,并且只有当我使用&#39;woningen&#39;作为表名时 - Zend_db only gives a error in my main module and only when I use 'woningen' as table name 当我将我的Zend_Db_Table_Abstract与select和join一起使用时,fetchAll返回我一行 - When i use my Zend_Db_Table_Abstract with select and join, fetchAll return me one row 在 Doctrine 中持久化实体时如何使用 DB 默认值? - How to use DB default when persist entity in Doctrine?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM