[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pear-doc
Subject:    [PEAR-DOC] [PEAR-BUG] Req #1998 [Opn->WFx]: please include this example in the online documentation
From:       danielc () analysisandsolutions ! com
Date:       2004-07-30 18:03:20
Message-ID: 20040730180320.53837.qmail () pb12 ! pair ! com
[Download RAW message or body]

Edit report at http://pear.php.net/bugs/bug.php?id=1998&edit=1

 ID:          1998
 Updated by:  danielc@analysisandsolutions.com
 Reported By: jon at latchkey dot com
-Status:      Open
+Status:      Wont fix
 Type:        Feature/Change Request
-Package:     DB
+Package:     Documentation
 PHP Version: Irrelevant
 Assigned To: danielc
 New Comment:

Sorry about the mistaken DB_FETCHMODE_ASSOC comment.

The getAssoc() documentation provides real world examples of how a
given result set would come out using each option.  The suggested
wording doesn't perform that task.

[Note: The bug was originally submitted with the summary of 
"DB_FETCHMODE_PRIMARY_KEY," which was a PEAR::DB feature request.  The
user then changed subject to "please include this example in the online
documentation."  I'm now changing the Pakcage to "Documentation."]


Previous Comments:
------------------------------------------------------------------------

[2004-07-30 13:36:38] jon at latchkey dot com

Ah ha! it is getAssoc() that does the trick.

The online documentation for getAssoc() is far more confusing than the
phpdoc documentation in the code.

     * For example, if the table "mytable" contains:
     *
     * <pre>
     *  ID      TEXT       DATE
     * --------------------------------
     *  1       'one'      944679408
     *  2       'two'      944679408
     *  3       'three'    944679408
     * </pre>
     *
     * Then the call getAssoc('SELECT id,text FROM mytable') returns:
     * <pre>
     *   array(
     *     '1' => 'one',
     *     '2' => 'two',
     *     '3' => 'three',
     *   )
     * </pre>
     *
     * ...while the call getAssoc('SELECT id,text,date FROM mytable')
returns:
     * <pre>
     *   array(
     *     '1' => array('one', '944679408'),
     *     '2' => array('two', '944679408'),
     *     '3' => array('three', '944679408')
     *   )
     * </pre>

------------------------------------------------------------------------

[2004-07-30 13:27:27] jon at latchkey dot com

By the way, if you are willing to accept the patch, I will even write
the code for you. Just let me know.

------------------------------------------------------------------------

[2004-07-30 13:10:32] jon at latchkey dot com

Hi Daniel,

Please actually read what I write and we will stop wasting each others
time.

According to the documentation, it says:

DB_FETCHMODE_ASSOC

Array
(
   [a] => 28
   [b] => hi
)

That is the 'COLUMN NAME' as the array key. 

I'm specifically asking for the 'PRIMARY KEY VALUE' to be the array
key.

jon

------------------------------------------------------------------------

[2004-07-30 12:59:39] danielc at analysisandsolutions dot com

DB_FETCHMODE_ASSOC

------------------------------------------------------------------------

[2004-07-30 12:46:16] jon at latchkey dot com

As far as I can tell, no it can't. The first item in the array is the
array index number, not the primary key.

For example, from the documentation:

http://pear.php.net/manual/en/package.database.db.intro-fetch.php

DB_FETCHMODE_ORDERED

Array
(
    [0] => 28
    [1] => hi
)

In this case, the primary key is element 0 in the array which is what I
don't want.

What I am asking for is:

Array
{
   [28] => array(0 => hi)
}

Right now, I have to write the following code to do that:

$result = $db->query();
foreach ($result as $r)
{
    $tmpResult[$r['POSITION_ID']] = 
        array('START_TIME' => $r['START_TIME'], 
              'USER_ID' => $r['USER_ID'], 
              'REQUESTED_BY' => $r['REQUESTED_BY'],
              'ASSIGNED_BY' => $r['ASSIGNED_BY'],
              'ASSIGNED_DATE' => $r['ASSIGNED_DATE'],
              'DELETED' => $r['DELETED'],
              'POSITION_NAME' => $r['POSITION_NAME'],
              'POSITION_ORDER' => $r['POSITION_ORDER'],
              'POSITION_ID' => $r['POSITION_ID']
              );
}

It would be nice if the DB api already had that functionality in it. If
there is a FETCHMODE that I'm missing, let me know.

thanks,

jon

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://pear.php.net/bugs/bug.php?id=1998

-- 
Edit this bug report at http://pear.php.net/bugs/bug.php?id=1998&edit=1

-- 
PEAR Documentation List Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic