Doctrine 原则:executeQuery()会添加额外的值作为回报
当我运行以下查询时:Doctrine 原则:executeQuery()会添加额外的值作为回报,doctrine,silex,Doctrine,Silex,当我运行以下查询时: $where = array( $request->get("order_item_id"), //an array with integers ); $types = array( \Doctrine\DBAL\Connection::PARAM_INT_ARRAY ); $sql = "SELECT id,store_id FROM order_items WHERE id IN (?) ORDER BY id"; $query = $app['
$where = array(
$request->get("order_item_id"), //an array with integers
);
$types = array(
\Doctrine\DBAL\Connection::PARAM_INT_ARRAY
);
$sql = "SELECT id,store_id FROM order_items WHERE id IN (?) ORDER BY id";
$query = $app['db']->executeQuery($sql, $where, $types);
$order_items = $query->fetchAll();
我明白了:
Array
(
[0] => Array
(
[id] => 1
[0] => 1
[store_id] => 11
[1] => 11
)
[1] => Array
(
[id] => 6
[0] => 6
[store_id] => 11
[1] => 11
)
[2] => Array
(
[id] => 11
[0] => 11
[store_id] => 11
[1] => 11
)
我不明白为什么要返回额外的0和1 VAL。试试:
$order_items = $query->fetchAssoc();
对于一行,只返回字段名
或者尝试将PDO::FETCH_ASSOC传递给fetchAll()函数。成功了!谢谢:$order\u items=$query->fetchAll(\PDO::FETCH\u ASSOC);