就项目规模而言,教条vs zend-db-table的速度和性能,什么时候应该在Zend项目中使用原则,何时使用zend-db-table?什么时候应该使用学说ORM和什么时候zend-db-table?
回答
任何ORM框架让你受益发展生产力,不执行效率。在这方面,学说与Zend_Db_Table没有什么不同。
如果您在Doctrine和Zend_Db_Table之间进行选择,请根据使代码更容易编写或更快的功能进行选择。
没有ORM框架能够自动进行数据库查询在一般情况下快。如果您需要高性能的数据库查询,您应该学会编写SQL查询,并根据需要运行的查询设计架构和索引以支持性能。
使用任何你最舒服,并会令你最有效的。您和您的开发人员可能是最昂贵的资源,如果需要购买额外的硬件,则可能比您不必担心将来可能出现的性能问题更便宜。
当然,您仍然需要执行基本的数据库优化,比如创建合理的索引等。但是我觉得那些“优化”不言而喻。
查询优化的重要考虑因素,如果学说使其自动和Zend-DB不能让它自动。 谢谢 – Yosef 2010-05-24 21:53:12
如果你有很多SQL查询和缺乏知识(对缓存或查询优化等一无所知)以及缺乏时间使用Zend_DB,它会更快,更容易被理解,对于你来说它已经足够好了 - 缺乏知识和时间并希望尽可能快的人。
但是如果你想要一个杀手ORM主义胜利。但它需要更多的时间和精力才能有效地使用。
如果你想成为一名数据库杀手,我们要离开话题。他们有区别。并不一定基于您使用的工具。 (DB一些杀手可能使用PDO本身和自己的车型,谁知道?)
原则可以帮助你定义一个更好的商业逻辑和ORM,但它是在内存和CPU长期绝对业绩的杀手。 Zend表格网关比Doctrine快5倍。而且你可以扩展Zend表格网关来删除一些数据类型解析器,这将使你获得5倍的改进,还能保留简单的ORM的好处。这里是我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;
}
}
- 1. 什么时候应该使用AWS,什么时候不使用
- 2. 什么时候应该使用Import-Package,什么时候应该使用Require-Bundle?
- 3. 什么时候使用__proto__和什么时候使用原型
- 4. 什么时候使用Ruby和什么时候使用PHP
- 5. 什么时候应该用Nunjucks和Angular?
- 6. 什么时候应该使用getElementById?
- 7. 什么时候应该使用_aligned_malloc()?
- 8. 什么时候应该使用GC.SuppressFinalize()?
- 9. 什么时候应该使用`use`?
- 10. 什么时候应该使用didFinishLaunchingWithOptions?
- 11. 什么时候应该使用模板
- 12. 什么时候应该使用可可?
- 13. 什么时候应该使用RESTful?
- 14. 什么时候应该使用const?
- 15. 什么时候应该使用git add?
- 16. 什么时候应该使用html5 sessionStorage?
- 17. 我什么时候应该使用javax.swing.SwingUtilities.invokeLater()?
- 18. 什么时候应该使用Solandra
- 19. 什么时候应该使用*,&,。 , - >?
- 20. 什么时候应该使用$(document).ready?
- 21. 什么时候应该使用scala.util.DynamicVariable?
- 22. 什么时候应该使用流?
- 23. 我什么时候应该使用UITableViewCellSeparatorStyleSingleLineEtched?
- 24. 什么时候应该使用FSharpFunc.Adapt?
- 25. 什么时候应该使用@android:id /?
- 26. 什么时候应该使用PostgreSQL中
- 27. 什么时候应该使用@property?
- 28. 什么时候应该使用getApplicationContext()。getBean?
- 29. 什么时候应该扩展NSDocument,什么时候应该扩展NSWindowController?
- 30. 我们什么时候应该上课,什么时候不应该上课
“没有ORM框架可以自动创建数据库”。对不起,我现在没有这个链接,但是我已经看到了使用PHP 5.3的Doctrine 2基准测试,这表明在某些情况下,它比本机PDO运行得更快。我知道,那些基准是邪恶的,但这是不可能的? – takeshin 2010-05-25 07:25:51
非常感谢。 – Yosef 2010-05-25 09:40:29
@takeshin:Doctrine 2使用事务管理和缓存来提高某些场景的性能。这不会使*查询*运行得更快。 – 2010-05-25 12:41:53