Hand made queries vs findDependentRowset

我怕爱的太早我们不能终老 提交于 2019-12-20 02:56:29

问题


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')

or going with the findDependentRowset method (Zend doc for 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'];
}

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?

Thanks


回答1:


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.

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.

See this question: PHP - Query single value per iteration or fetch all at start and retrieve from array?



来源:https://stackoverflow.com/questions/4433910/hand-made-queries-vs-finddependentrowset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!