php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57285 fetchAll PDO::FETCH_GROUP|PDO::FETCH_COLUMN,2
Submitted: 2006-10-07 15:05 UTC Modified: 2016-06-18 14:29 UTC
From: jakoch at web dot de Assigned: cmb (profile)
Status: Not a bug Package: *General Issues
PHP Version: 5.1.2 OS:
Private report: No CVE-ID: None
 [2006-10-07 15:05 UTC] jakoch at web dot de
Description:
------------
Hello,

this might be a bug.

I'm trying to fetch an associative array grouped by the values of a specified column. In my case the column 'name'.

How to group values by the second column ?

Expected result:
----------------
$res = $stmt->fetchALL(PDO::FETCH_COLUMN,1|PDO::FETCH_GROUP);

array
      'configs' => 
        array
          'submodule_id' => '17' (length=2)
          'name' => 'configs' (length=7)
          'file_name' => 'configs.module.php' (length=18)
          'class_name' => 'module_admin_configs' (length=20)

Actual result:
--------------
$res = $stmt->fetchALL(PDO::FETCH_NAMED);

Return:
array
0 => 
        array
          'submodule_id' => '17' (length=2)
          'name' => 'configs' (length=7)
          'file_name' => 'configs.module.php' (length=18)
          'class_name' => 'module_admin_configs' (length=20)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-10-07 15:12 UTC] jakoch at web dot de
actual result is

array 
 empty
 [2007-01-10 11:41 UTC] arne dot anka at gmx dot net
same here:
$query="SELECT col1,col2 FROM table";
$db->query($query)->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_GROUP);

result:
Array
(
    [1] => Array
        (
            [0] => firmaA
        )
    [2] => Array
        (
            [0] => firmaB
        )
    [3] => Array
        (
            [0] => firmaC
        )
    [4] => Array
        (
            [0] => firmaD
        )
)

expected:
Array
(
    [1] => firmaA
    [2] => firmaB
    [3] => firmaC
    [4] => firmaD
)
 [2016-06-18 14:29 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Package: PDO +Package: *General Issues -Assigned To: +Assigned To: cmb
 [2016-06-18 14:29 UTC] cmb@php.net
> this might be a bug.

It doesn't appear so.

> How to group values by the second column ?

Specify the column index as $fetch_argument.

> $stmt->fetchALL(PDO::FETCH_COLUMN,1|PDO::FETCH_GROUP);

Should be

  $stmt->fetchALL(PDO::FETCH_COLUMN|PDO::FETCH_GROUP,1);
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 11:01:28 2024 UTC