为了账号安全,请及时绑定邮箱和手机立即绑定

如何使用SELECT请求获取数据

如何使用SELECT请求获取数据

PHP
绝地无双 2021-09-05 16:35:25
我正在尝试在我的数据库中显示运营商的统计数据。当我调用该函数但出现如下错误时:class: "Doctrine\DBAL\Exception\SyntaxErrorException"message: "An exception occurred while executing 'select count(cod_ser) TOTAL FROM public.tiers_datamart period =06-2019':↵↵SQLSTATE[42601]:我的代码是这样的:public function getTotalDatabyMonth($date, $type, $filtre) {        $em = $this->getDoctrine()->getManager('dbStat')->getConnection();        if($filtre == null) {            $restriction = "period =".$date;        }else {            $restriction = $type." = ".$filtre." AND period = ".$date;        }        $rawSql = "select count(".$type.") TOTAL FROM public.tiers_datamart ".$restriction;                $stmt = $em->prepare($rawSql);        $stmt->execute();           $result = $stmt->fetchAll();            return intval($result[0]['total']);    }    public function getTotalDatabyMonths($dates, $type, $filtre) {        $totalDatas = [];        foreach($dates as $date){            $total = $this->getTotalDatabyMonth($date, $type, $filtre);            array_push($totalDatas, $total);        }        return $totalDatas;    }我调用函数 'data'=> $this->getTotalDatabyMonths($dataFormats[1], "cod_ser", $restriction)我试图在方法中替换$filtreby但它返回相同的值 12 次。$restrictiongetTotalDatabyMonths()
查看完整描述

1 回答

?
HUX布斯

TA贡献1876条经验 获得超6个赞

$rawSql = "select count(".$type.") TOTAL FROM public.tiers_datamart WHERE ".$restriction;

添加 WHERE 就可以了。


查看完整回答
反对 回复 2021-09-05
  • 1 回答
  • 0 关注
  • 167 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信