mirror of
https://github.com/dg/dibi.git
synced 2025-08-03 20:57:36 +02:00
fixed example
This commit is contained in:
@@ -54,12 +54,14 @@ dump($assoc);
|
|||||||
|
|
||||||
// fetch complete result set like pairs key => value
|
// fetch complete result set like pairs key => value
|
||||||
echo "<h2>fetchPairs('product_id', 'title')</h2>\n";
|
echo "<h2>fetchPairs('product_id', 'title')</h2>\n";
|
||||||
|
$res = dibi::query('SELECT * FROM products');
|
||||||
$pairs = $res->fetchPairs('product_id', 'title');
|
$pairs = $res->fetchPairs('product_id', 'title');
|
||||||
dump($pairs);
|
dump($pairs);
|
||||||
|
|
||||||
|
|
||||||
// fetch row by row
|
// fetch row by row
|
||||||
echo "<h2>using foreach</h2>\n";
|
echo "<h2>using foreach</h2>\n";
|
||||||
|
$res = dibi::query('SELECT * FROM products');
|
||||||
foreach ($res as $n => $row) {
|
foreach ($res as $n => $row) {
|
||||||
dump($row);
|
dump($row);
|
||||||
}
|
}
|
||||||
@@ -73,14 +75,16 @@ $res = dibi::query('
|
|||||||
INNER JOIN customers USING (customer_id)
|
INNER JOIN customers USING (customer_id)
|
||||||
');
|
');
|
||||||
|
|
||||||
echo "<h2>fetchAssoc('customers.name|products.title')</h2>\n";
|
echo "<h2>fetchAssoc('name|title')</h2>\n";
|
||||||
$assoc = $res->fetchAssoc('customers.name|products.title'); // key
|
$assoc = $res->fetchAssoc('name|title'); // key
|
||||||
dump($assoc);
|
dump($assoc);
|
||||||
|
|
||||||
echo "<h2>fetchAssoc('customers.name[]products.title')</h2>\n";
|
echo "<h2>fetchAssoc('name[]title')</h2>\n";
|
||||||
$assoc = $res->fetchAssoc('customers.name[]products.title'); // key
|
$res = dibi::query('SELECT * FROM products INNER JOIN orders USING (product_id) INNER JOIN customers USING (customer_id)');
|
||||||
|
$assoc = $res->fetchAssoc('name[]title'); // key
|
||||||
dump($assoc);
|
dump($assoc);
|
||||||
|
|
||||||
echo "<h2>fetchAssoc('customers.name->products.title')</h2>\n";
|
echo "<h2>fetchAssoc('name->title')</h2>\n";
|
||||||
$assoc = $res->fetchAssoc('customers.name->products.title'); // key
|
$res = dibi::query('SELECT * FROM products INNER JOIN orders USING (product_id) INNER JOIN customers USING (customer_id)');
|
||||||
|
$assoc = $res->fetchAssoc('name->title'); // key
|
||||||
dump($assoc);
|
dump($assoc);
|
||||||
|
Reference in New Issue
Block a user