symfony中的请求计数sql返回布尔值不是整数

时间:2017-03-10 10:39:52

标签: php sql symfony doctrine-orm dbal

在symfony中的

我想从数据库中的表中获取计数,但它返回boolean!

    
    $sql = "....";
    $em = $this->getDoctrine()->getManager();
    $stmt = $em->getConnection()->prepare($sql);   
    $stmt->execute();


    $res = $stmt->fetchAll();
    foreach ($res as $key => $value) {
               $resultatRequete = "SELECT count(id) from inscriptions where seance_id = 
 '".$value['seance_id']."' and is_confirmed is not null";

                     $stmt2 = $em->getConnection()->prepare($resultatRequete);
                     $result_req = $stmt2->execute();
                     $res[$key]["count_inscrit"] = $result_req ;
    }
    return $res;

1 个答案:

答案 0 :(得分:2)

execute方法返回一个布尔值以便成功/失败,然后你应该获取结果,例如:

                 // you can check on success ...
                 $success = $stmt2->execute();

                 $result_req = $stmt2->fetch();
                 $res[$key]["count_inscrit"] = $result_req ;

希望这个帮助