Reputation: 103
I have little problem with stored procedure (pgsql). In the return of this procedure, the array return has special construction that unusable for me in this way.
I try many different way to call the SP or Hydratation method but always same kind of return.
Can you help me on this ?
My specs : I want an array as return (just value needed), but the SP return an array of array with one line by result like this (var_dumped):
array (size=3)
0 =>
array (size=1)
'get_structure_utilisateur' => int 2
1 =>
array (size=1)
'get_structure_utilisateur' => int 1
2 =>
array (size=1)
'get_structure_utilisateur' => int 10
I would like something like :
array (size=3)
0 => 2
1 => 1
2 => 10
I try this or this, same result or little differences :
$query = $this->getEntityManager()
->getConnection()
->query('select admin.get_structure_utilisateur(3, 1)')
->fetchAll();
or
$sql = "select admin.get_structure_utilisateur(:utilisateurId, :clientId)";
$rsm = new ResultSetMapping;
$rsm->addScalarResult('get_structure_utilisateur', 'structures');
$query = $this->getEntityManager()->createNativeQuery($sql, $rsm)
->setParameter('clientId', 1)
->setParameter('utilisateurId', 3);
$query->getResult(Query::HYDRATE_SCALAR);// I Try some other hydratation method
Thanks
Upvotes: 1
Views: 1082
Reputation: 12033
Try to use fetchColumn.
$em = $this->getEntityManager();
$db = $em->getConnection();
$stmt = $db->prepare('select admin.get_structure_utilisateur(:utilisateurId, :clientId)');
$stmt->bindValue('clientId', 1);
$stmt->bindValue('utilisateurId', 3);
$stmt->execute();
while (($row = $stmt->fetchColumn()) !== false) {
print $row;
}
Upvotes: 3