mirror of
https://github.com/dg/dibi.git
synced 2025-07-10 00:56:24 +02:00
tests: Nette\Debugger replaced with Tracy, examples requires PHP 5.3
This commit is contained in:
@ -4,10 +4,11 @@
|
||||
|
||||
<?php
|
||||
|
||||
require dirname(__FILE__) . '/Nette/Debugger.php';
|
||||
require dirname(__FILE__) . '/../dibi/dibi.php';
|
||||
require __DIR__ . '/Tracy/tracy.phar';
|
||||
require __DIR__ . '/../dibi/dibi.php';
|
||||
|
||||
Tracy\Debugger::enable();
|
||||
|
||||
ndebug();
|
||||
|
||||
dibi::connect(array(
|
||||
'driver' => 'sqlite3',
|
||||
@ -30,40 +31,40 @@ product_id | title
|
||||
// fetch a single row
|
||||
echo "<h2>fetch()</h2>\n";
|
||||
$row = dibi::fetch('SELECT title FROM products');
|
||||
dump($row); // Chair
|
||||
Tracy\Dumper::dump($row); // Chair
|
||||
|
||||
|
||||
// fetch a single value
|
||||
echo "<h2>fetchSingle()</h2>\n";
|
||||
$value = dibi::fetchSingle('SELECT title FROM products');
|
||||
dump($value); // Chair
|
||||
Tracy\Dumper::dump($value); // Chair
|
||||
|
||||
|
||||
// fetch complete result set
|
||||
echo "<h2>fetchAll()</h2>\n";
|
||||
$all = dibi::fetchAll('SELECT * FROM products');
|
||||
dump($all);
|
||||
Tracy\Dumper::dump($all);
|
||||
|
||||
|
||||
// fetch complete result set like association array
|
||||
echo "<h2>fetchAssoc('title')</h2>\n";
|
||||
$res = dibi::query('SELECT * FROM products');
|
||||
$assoc = $res->fetchAssoc('title'); // key
|
||||
dump($assoc);
|
||||
Tracy\Dumper::dump($assoc);
|
||||
|
||||
|
||||
// fetch complete result set like pairs key => value
|
||||
echo "<h2>fetchPairs('product_id', 'title')</h2>\n";
|
||||
$res = dibi::query('SELECT * FROM products');
|
||||
$pairs = $res->fetchPairs('product_id', 'title');
|
||||
dump($pairs);
|
||||
Tracy\Dumper::dump($pairs);
|
||||
|
||||
|
||||
// fetch row by row
|
||||
echo "<h2>using foreach</h2>\n";
|
||||
$res = dibi::query('SELECT * FROM products');
|
||||
foreach ($res as $n => $row) {
|
||||
dump($row);
|
||||
Tracy\Dumper::dump($row);
|
||||
}
|
||||
|
||||
|
||||
@ -77,14 +78,14 @@ $res = dibi::query('
|
||||
|
||||
echo "<h2>fetchAssoc('name|title')</h2>\n";
|
||||
$assoc = $res->fetchAssoc('name|title'); // key
|
||||
dump($assoc);
|
||||
Tracy\Dumper::dump($assoc);
|
||||
|
||||
echo "<h2>fetchAssoc('name[]title')</h2>\n";
|
||||
$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);
|
||||
Tracy\Dumper::dump($assoc);
|
||||
|
||||
echo "<h2>fetchAssoc('name->title')</h2>\n";
|
||||
$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);
|
||||
Tracy\Dumper::dump($assoc);
|
||||
|
Reference in New Issue
Block a user