【问题标题】:symfony2: Native query with doctrinesymfony2:使用学说的本机查询
【发布时间】:2014-12-20 10:05:54
【问题描述】:

我正在尝试学说中的原生查询(真正的原生)。

public function recupererNoms()
{
    $sql = 'SELECT id, nom FROM table;';
    $stmt = $this->getEntityManager()->getConnection()->prepare($sql);
    $stmt->execute();
    return $stmt->fetchAll();
}

此查询返回:

array(4) { ["id"]=> string(1) "1" [0]=> string(1) "1" ["nom"]=> string(4) "toto" [1]=> string(4) "toto" }

信息在此返回的表中以某种方式重复。例如,在我的 sql 请求中,我指定了名称并得到了["nom"]=> string(4) "toto" [1]=> string(4) "toto"。如何摆脱 [1]=> string(4) "toto"["id"]=> string(1) "1" [0]=> string(1) "1"

【问题讨论】:

    标签: symfony doctrine-orm


    【解决方案1】:

    试试

    return $stmt->fetchAll(\PDO::FETCH_ASSOC);
    

    其他选项请查看PDOStatement::fetch

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-04
      • 1970-01-01
      • 1970-01-01
      • 2013-01-18
      • 1970-01-01
      相关资源
      最近更新 更多