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_QuickForm2 » Bug #8060

HTML_QuickForm_select -> loadDbResult Support MDB2

Details

Request #8060HTML_QuickForm_select -> loadDbResult Support MDB2
Submitted2006-06-28 16:47 UTC
Fromdvilches at gmail dot com
StatusWont fix
PackageHTML_QuickForm2
PHP VersionIrrelevant
OSIrrelevant
Roadmaps(Not assigned)

Comments

[2006-06-28 16:47 UTC] dvilches at gmail dot com

Description:
------------
I changed the method loadDbResult in HTML_QuickForm_select.

Test script:
---------------
require_once 'MDB2.php';
$dsn = array('phptype' => DB_PHPTYPE,
'username' => DB_USER,
'password' => DB_PWD,
'hostspec' => DB_HOST,
'database' => DB_DATABASE,
);
$db = MDB2::factory($dsn);
if (Pear::isError($db)){
die($db->getMessage());
}
$db->setFetchMode(MDB2_FETCHMODE_ASSOC);

$sql = "Select table_id, descrip From table";
$element = &HTML_QuickForm::createElement('select', 'table_id', 'Descrip');
$result = $db->query($sql);
$element->addOption('','');
$element->loadDbResult($result, 'descrip', 'table_id'); $element->toHtml();

The change of this method is:

if (!is_object($result) || !is_a($result, 'db_result')) {
....

by

if (!is_object($result) || (!is_a($result, 'db_result') && !is_a($result, 'mdb2_result'))) {
...

And works for me...

Expected result:
----------------
<select name="table_id">
<option value=""></option>
<option value="1" selected="selected">Descrip 1</option>
<option value="2">Descrip 2</option>
<option value="3">Descrip 3</option>
</select>

Actual result:
--------------
<select name="table_id">
<option value=""></option>
</select>

[2006-07-12 11:47 UTC] dvilches at gmail dot com

I changed the bug type for this item.

[2006-11-10 11:34 UTC] buye at libero dot it

Also changed this code in method loadDbResult for supporting MDB2:

function loadDbResult(&$result, $textCol=null, $valueCol=null, $values=null)
{
if (!is_object($result) || !is_a($result, 'db_result') && !is_a($result, 'mdb2_result')) {
return PEAR::raiseError('Argument 1 of HTML_Select::loadDbResult is not a valid DB_result');
}
if (isset($values)) {
$this->setValue($values);
}
if (is_a($result, 'db_result'))
{
$fetchMode = ($textCol && $valueCol) ? DB_FETCHMODE_ASSOC : DB_FETCHMODE_ORDERED;
}
else if (is_a($result, 'mdb2_result'))
{
$fetchMode = ($textCol && $valueCol) ? MDB2_FETCHMODE_ASSOC : MDB2_FETCHMODE_ORDERED;
}
while (is_array($row = $result->fetchRow($fetchMode)) ) {
if (($fetchMode == DB_FETCHMODE_ASSOC) || ($fetchMode == MDB2_FETCHMODE_ASSOC)){
$this->addOption($row[$textCol], $row[$valueCol]);
} else {
$this->addOption($row[0], $row[1]);
}
}
return true;
} // end func loadDbResult

Remember to use getDatabaseResult() for saving result of a query.