1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-05 13:47:33 +02:00
This commit is contained in:
David Grudl
2007-04-25 08:19:03 +00:00
parent 7c693a26fb
commit d03f60c43c

View File

@@ -238,17 +238,25 @@ abstract class DibiResult implements IteratorAggregate, Countable
/**
* Fetches all records from table like $key => $value pairs
* @param string associative key
* @param string value
* @return array
*/
final function fetchPairs($key, $value)
final function fetchPairs($key=NULL, $value=NULL)
{
@$this->seek(0);
$rec = $this->fetch();
if (!$rec)
return array(); // empty resultset
if (!array_key_exists($key, $rec) ||
!array_key_exists($value, $rec)) return FALSE;
if ($value === NULL) {
$tmp = array_keys($rec);
$key = $tmp[0];
$value = $tmp[1];
} else {
if (!array_key_exists($key, $rec)) return FALSE;
if (!array_key_exists($value, $rec)) return FALSE;
}
if (!$rec) return array(); // empty resultset
$arr = array();
do {