我使用symfony2创建一个应用程序,但一度陷入困境。在我之前的应用程序中,我使用了MySQL和PHP5。但现在我在symfony2中制作相同的应用程序。我不知道如何在学说中使用time_to_sec函数。这是我的代码。
public function hitsPerTimeAction($customer=null, $token=null, $cdn, $domain, $dateFrom, $dateTo, $tb, $frequency, $db) {
$data=array();
if($db == "DB1"){
$rds = "rds1";
}else{
$rds = "rds2";
}
$em = $this->getDoctrine()->getManager($rds);
if($frequency == "1 hour"){
$lesVolumes = $em->createQuery("select concat(v.date,'',sec_to_time(time_to_sec(concat(v.date,' ',v.time))time_to_sec(concat(v.date,' ',v.time))%(60*60)))
as 'atime',sum(v.count) as 'volume' from AppBundle:Hitspt$tb v where v.domain like'%$domain%' and
v.date between '$date From' and '$dateTo' and v.cdn='$cdn' group by atime");
$results = $lesVolumes->getArrayResult();
$volume =array();
$time = array();
$i=0;
foreach($results as $result){
$volume[$i]=$result["volume"];
//$time[$i]=$result["time"].' - '.$result["date"];
$time[$i]=$result["atime"];
$i++;
}
$response= new JsonResponse(array("volume" => $volume, "time" => $time));
$response->headers->set('Access-Control-Allow-Origin','*');
return $response;
}
}