1
0
mirror of https://github.com/dg/dibi.git synced 2025-02-23 10:26:21 +01:00
php-dibi/examples/fetch.php
David Grudl ac980fe8c9 + DibiResult::fetchAll()
* changed year in headers (2007)
2007-01-08 00:55:11 +00:00

50 lines
966 B
PHP

<pre>
<?php
require_once '../dibi/dibi.php';
dibi::$debug = true;
// mysql
dibi::connect(array(
'driver' => 'mysql',
'host' => 'localhost',
'username' => 'root',
'password' => 'xxx', // change to real password!
'database' => 'test',
'charset' => 'utf8',
));
$res = dibi::query('SELECT * FROM table');
if (!$res) die('SQL error');
// fetch a single value
$value = $res->fetchSingle();
// fetch complete result set
$all = $res->fetchAll();
// fetch complete result set like association array
$assoc = $res->fetchAssoc('id');
$assoc = $res->fetchAssoc('id', 'id2');
// fetch complete result set like pairs key => value
$pairs = $res->fetchPairs('id', 'name');
// fetch row by row
foreach ($res as $row => $fields) {
print_r($fields);
}
// fetch row by row with defined offset and limit
foreach ($res->getIterator(2, 3) as $row => $fields) {
print_r($fields);
}
?>