1
0
mirror of https://github.com/dg/dibi.git synced 2025-07-15 11:36:22 +02:00

Changed symbols for fetchAssoc: # means index, = means record field

This commit is contained in:
David Grudl
2007-11-18 09:16:54 +00:00
parent 58ed8d34f4
commit 981a1adaad
2 changed files with 10 additions and 10 deletions

View File

@ -30,7 +30,7 @@
* $table = $result->fetchAll(); * $table = $result->fetchAll();
* $pairs = $result->fetchPairs(); * $pairs = $result->fetchPairs();
* $assoc = $result->fetchAssoc('id'); * $assoc = $result->fetchAssoc('id');
* $assoc = $result->fetchAssoc('active', 'id'); * $assoc = $result->fetchAssoc('active,#,id');
* *
* unset($result); * unset($result);
* </code> * </code>
@ -236,7 +236,7 @@ class DibiResult extends NObject implements IteratorAggregate, Countable
/** /**
* Fetches all records from table and returns associative tree * Fetches all records from table and returns associative tree
* Associative descriptor: assoc1,*,assoc2,#,assco3 * Associative descriptor: assoc1,#,assoc2,=,assco3
* builds a tree: $data[value1][index][value2]['assoc3'][value3] = {record} * builds a tree: $data[value1][index][value2]['assoc3'][value3] = {record}
* *
* @param string associative descriptor * @param string associative descriptor
@ -254,7 +254,7 @@ class DibiResult extends NObject implements IteratorAggregate, Countable
// check fields // check fields
foreach ($assoc as $as) { foreach ($assoc as $as) {
if ($as !== '*' && $as !== '#' && !array_key_exists($as, $row)) { if ($as !== '#' && $as !== '=' && !array_key_exists($as, $row)) {
throw new InvalidArgumentException("Unknown column '$as' in associative descriptor"); throw new InvalidArgumentException("Unknown column '$as' in associative descriptor");
} }
} }
@ -268,7 +268,7 @@ class DibiResult extends NObject implements IteratorAggregate, Countable
} }
$last = count($assoc) - 1; $last = count($assoc) - 1;
if ($assoc[$last] === '#') unset($assoc[$last]); if ($assoc[$last] === '=') unset($assoc[$last]);
// make associative tree // make associative tree
do { do {
@ -276,10 +276,10 @@ class DibiResult extends NObject implements IteratorAggregate, Countable
// iterative deepening // iterative deepening
foreach ($assoc as $i => $as) { foreach ($assoc as $i => $as) {
if ($as === '*') { // indexed-array node if ($as === '#') { // indexed-array node
$x = & $x[]; $x = & $x[];
} elseif ($as === '#') { // "record" node } elseif ($as === '=') { // "record" node
if ($x === NULL) { if ($x === NULL) {
$x = $row; $x = $row;
$x = & $x[ $assoc[$i+1] ]; $x = & $x[ $assoc[$i+1] ];

View File

@ -83,10 +83,10 @@ $assoc = $res->fetchAssoc('customers.name,products.title'); // key
print_r($assoc); print_r($assoc);
echo '<hr>'; echo '<hr>';
$assoc = $res->fetchAssoc('customers.name,*,products.title'); // key
print_r($assoc);
echo '<hr>';
$assoc = $res->fetchAssoc('customers.name,#,products.title'); // key $assoc = $res->fetchAssoc('customers.name,#,products.title'); // key
print_r($assoc); print_r($assoc);
echo '<hr>'; echo '<hr>';
$assoc = $res->fetchAssoc('customers.name,=,products.title'); // key
print_r($assoc);
echo '<hr>';