1

我对存储过程(pgsql)没有什么问题。在这个过程的返回中,数组返回具有特殊的结构,我无法以这种方式使用。

我尝试了许多不同的方式来调用 SP 或 Hydratation 方法,但总是返回相同的类型。

你能帮我解决这个问题吗?

我的规格:我想要一个数组作为返回值(只需要值),但是 SP 返回一个数组数组,其中一行结果如下(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

我想要类似的东西:

array (size=3)
    0 => 2
    1 => 1
    2 => 10

我尝试这个或这个,结果相同或差异很小:

$query = $this->getEntityManager()
    ->getConnection()
    ->query('select admin.get_structure_utilisateur(3, 1)')
    ->fetchAll();

或者

$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

谢谢

4

1 回答 1

3

尝试使用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;
    }
于 2013-08-12T15:18:41.350 回答