PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » HTML » HTML_QuickForm » Bug #7487

select->loadDbResult() incorrectly sets DB_FETCHMODE_DEFAULT

Details

Submitted2006-04-25 18:38 UTC
Fromwebmaster at metapundit dot net
StatusDuplicate
PackageHTML_QuickForm
PHP Version4.4.2
Roadmaps(Not assigned)

Comments

[2006-04-25 18:38 UTC] webmaster at metapundit dot net

Description:
------------
select->loadDbResult() takes a DB_Result and two option fields. If the fields are not specified, the first two columns in the result are supposed to be used for the text and values respectively. If the arguments are not specified, however, the fetchmode of the DB is set to DB_FETCHMODE_DEFAULT on line 382 of select.php before attempting to read the row array with indexes 0 and 1. If the DB has had it's default fetchmode set to anything other than DB_FETCHMODE_ORDERED the row array may not be a numerically indexed array (or an array at all).

This is incorrect. Someone else noted this on the comments for Bug 5705, but line 382 should be

$fetchMode = ($textCol && $valueCol) ? DB_FETCHMODE_ASSOC :
DB_FETCHMODE_ORDERED;

to guarantee that you will be getting back a numerically indexed array.

Test script:
---------------
setFetchMode(DB_FETCHMODE_ASSOC);
$res = $db->query('select username, id from auth');
$f = new HTML_Quickform();
$sel = &$f->addElement('select', 'foo');
$sel->loadDbResult($res);
echo $f->toHTML();
#end test script.
?>
Following is diff file that can be applied to select.php
366c366
$fetchMode = ($textCol && $valueCol) ? DB_FETCHMODE_ASSOC : DB_FETCHMODE_ORDERED;

Expected result:
----------------
I expect to see a form with a select box filled with values from my table. Instead I get a form with blank values/text pairs with an option for each row returned from my query.

Actual result:
--------------

</form>