2

in symfony I want to get count from table in database but it return 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;
Fredj
  • 59
  • 2
  • 9

1 Answers1

2

The execute method return a boolean in order to success/failure, then you should fetch the result, as example:

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

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

Hope this help

Matteo
  • 37,680
  • 11
  • 100
  • 115
  • tha result is for example : count_inscrit: { count(id): "13" } how to make it count_inscri: "13" !! – Fredj Mar 10 '17 at 11:15
  • so the results is an array, so try to select as `SELECT count(id) as count` then fetch as element as `$result_req['count']` – Matteo Mar 10 '17 at 11:17