나는 카운트 모든 도시 및 사용 기능을 얻을로 데이터베이스에 연결 감소 :는 교리와 심포니
foreach ($cities as $city) {
echo $city->getName() . '|' . CityTable::getInstance()->getCount($city->getId(), a). '|' . CityTable::getInstance()->getCount($city->getId(), b). '|' . CityTable::getInstance()->getCount($city->getId(), c);
}
public function getCount($id, $num)
{
$q = $this->createQuery('u')
->where('city_id = ?', $id)
->andWhere('num = ?', $num)
->execute();
return count($q);
}
것은이 확인 작업을하지만, 많은 발생이 데이터베이스에 연결합니다. foreach의 각 반복에서 세 번 호출되는 함수 getCount입니다. 내가 도시의 도시를 1000 개 이상의 도시에 있다면 나는 데이터베이스에 10000 개가 넘는 쿼리를 가지고있다. 어떻게 줄일 수 있습니까?
이 나에게 도움이되지 –