1

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

Pouzor
  • 103
  • 1
  • 9

1 Answers1

3

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;
    }
Alexey B.
  • 11,965
  • 2
  • 49
  • 73
  • Thx, but it's pretty the same things because I must look over all result for re-arranging the datas. I can do the same thing with the other methods, I just look for a proper way. Maybe with custom hydradation – Pouzor Aug 12 '13 at 15:39
  • If you are looking for optimizations I must disappoint you - internally all hydrators do the same things - iterate over all results. Look at [ArrayHydrator](https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php) – Alexey B. Aug 12 '13 at 17:23