Req #8060 [Opn->WFx]: HTML_QuickForm_select -> loadDbResult Support MDB2
| From: | borz_off at cs dot msu dot su | Date: | Sun, 08 Apr 2012 12:16:49 +0000 |
| Subject: | Req #8060 [Opn->WFx]: HTML_QuickForm_select -> loadDbResult Support MDB2 | ||
| References: | 1 | Groups: | php.pear.bugs |
| Request: | Send a blank email to pear-bugs+get-8534@lists.php.net to get a copy of this message | ||
Edit report at https://pear.php.net/bugs/bug.php?id=8060&edit=1
ID: 8060
Updated by: borz_off@cs.msu.su
Reported By: dvilches at gmail dot com
Summary: HTML_QuickForm_select -> loadDbResult Support MDB2
-Status: Open
+Status: Wont fix
Type: Feature/Change Request
Package: HTML_QuickForm2
Operating System: Irrelevant
Package Version: 3.2.6
PHP Version: Irrelevant
Roadmap Versions:
New Comment:
-Status: Open
+Status: Wont fix
Most of DB abstraction layers implement a fetchAll() method or some
analog. These can return an associative array that can be fed to
loadOptions(), so no sense bloating the element with additional code.
Previous Comments:
------------------------------------------------------------------------
[2006-11-10 06:34:22] 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.
------------------------------------------------------------------------
[2006-10-06 11:45:36] avb
Feature requests go to HTML_QuickForm2
------------------------------------------------------------------------
[2006-07-12 07:47:13] dvilches at gmail dot com
I changed the bug type for this item.
------------------------------------------------------------------------
[2006-06-28 12:47:54] 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>
------------------------------------------------------------------------
--
Edit this bug report at https://pear.php.net/bugs/bug.php?id=8060&edit=1