Fetching Examples | dibi

'sqlite', 'database' => 'data/sample.sdb', )); /* TABLE products product_id | title -----------+---------- 1 | Chair 2 | Table 3 | Computer */ // fetch a single row echo "

fetch()

\n"; $row = dibi::fetch('SELECT title FROM products'); Debugger::dump($row); // Chair // fetch a single value echo "

fetchSingle()

\n"; $value = dibi::fetchSingle('SELECT title FROM products'); Debugger::dump($value); // Chair // fetch complete result set echo "

fetchAll()

\n"; $all = dibi::fetchAll('SELECT * FROM products'); Debugger::dump($all); // fetch complete result set like association array echo "

fetchAssoc('title')

\n"; $res = dibi::query('SELECT * FROM products'); $assoc = $res->fetchAssoc('title'); // key Debugger::dump($assoc); // fetch complete result set like pairs key => value echo "

fetchPairs('product_id', 'title')

\n"; $pairs = $res->fetchPairs('product_id', 'title'); Debugger::dump($pairs); // fetch row by row echo "

using foreach

\n"; foreach ($res as $n => $row) { Debugger::dump($row); } // more complex association array $res = dibi::query(' SELECT * FROM products INNER JOIN orders USING (product_id) INNER JOIN customers USING (customer_id) '); echo "

fetchAssoc('customers.name|products.title')

\n"; $assoc = $res->fetchAssoc('customers.name|products.title'); // key Debugger::dump($assoc); echo "

fetchAssoc('customers.name[]products.title')

\n"; $assoc = $res->fetchAssoc('customers.name[]products.title'); // key Debugger::dump($assoc); echo "

fetchAssoc('customers.name->products.title')

\n"; $assoc = $res->fetchAssoc('customers.name->products.title'); // key Debugger::dump($assoc);