手工查询 vs findDependentRowset [英] Hand made queries vs findDependentRowset

查看:25
本文介绍了手工查询 vs findDependentRowset的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 Zend 构建了一个相当大的应用程序,我想知道哪个更好,手动构建查询(使用 Zend 对象模型)

I have built a pretty big application with Zend and i was wondering which would be better, building query by hand (using the Zend object model)

$db->select()
   ->form('table')
   ->join('table2',
          'table.id = table2.table_id')

或使用 findDependentRowset 方法(findDependentRowSet 的 Zend 文档).

我想知道,因为我做了一个测试来获取多个表的数据并显示一个表中的所有信息,而 findDependentRowset 似乎运行得更慢.我可能是错的,但我想每次 findDependentRowset 被调用时都会产生一个新的查询:

I was wondering since i did a test to fetch data over multiple tables and display all the informations from a table and the findDependentRowset seemed to run slower. I might be wrong but i guess it makes a new query every time findDependentRowset is called as in :

$table1 = new Model_Table1;
$rowset = $table1-fetchAll();
foreach($rowset as $row){
    $table2data = $row->findDependentRowset('Model_Table2', 'Map');

    echo $row['field'] . ' ' . $table2data['field'];
}

那么,哪一个更好,有没有一种方法可以使用 findDependentRowset 来构建可以跨越 5 个表的复杂查询,这些查询的运行速度与手工查询一样快?

So, which one is better and is there a way using findDependentRowset to build complexes queries that could span over 5 tables which would run as fast as a hand made query?

谢谢

推荐答案

通常,构建您自己的查询是最好的方法,因为 Zend 将只创建一个对象(或一组对象)并且只执行一个查询.

Generally, build your own query is the best way to go, because zend will create just one object (or set of objects) and do just one query.

如果您使用 findDependentRowset Zend 将执行另一个查询并使用每次调用的结果构建另一个对象(或集合).

If you use findDependentRowset Zend will perform another query and build another object (or set) with the result for each call.

你应该只在非常特殊的情况下使用它.

You should use this only in very specific cases.

看到这个问题:PHP - 每次迭代查询单个值还是在开始时获取所有值并从数组中检索?

这篇关于手工查询 vs findDependentRowset的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆