我目前正在重构一个遗留应用程序并逐个转换为 zend 框架 1.12。
我对如何将其转换为 zend db 感到头疼,有没有一种方法可以在一个查询中完成?
现在我看到它首先获取文件夹列表,然后为每个文件夹运行一个额外的查询......作为一个查询运行它会提高性能,对吗?
$folders_query = DB::Query("select * from contacts_folders order by sort_order, name");
while($folders = DB::FetchArray($folders_query)){
$counts_total = DB::QueryOne("SELECT count(cm.messages_id) AS total
FROM contacts_basics cb, contacts_messages cm
WHERE cb.contacts_id = cm.contacts_id
AND cm.folders_id = '" . $folders['folders_id'] . "'
AND cm.status = '1'
AND cm.mark = '0'");
if ($counts_total >0){
$folders_name = '<strong>' . $folders['name'] . ' (' . $counts_total . ')</strong>';
} else {
$folders_name = $folders['name'];
}
echo '<li><a href="messages.php?fID=' . $folders['folders_id'] . '">';
echo $folders_name;
echo '</a></li>';
}