<?php
$pdo = new pdo(
'sqlite::memory:',
null,
null,
[
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_EMULATE_PREPARES => false,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_GROUP | PDO::FETCH_FUNC
]
);
$pdo->exec('create table x(sort int, foo text, bar text)');
$pdo->exec("insert into x(sort, foo, bar) values (1, 'a', 'b'), (1, 'c', 'd'), (2, 'e', 'f')");
$pdo->query('select * from x')
->fetchAll(
PDO::FETCH_GROUP | PDO::FETCH_FUNC,
function () {
static $i = 0;
$i++;
echo "row $i\n";
var_dump(func_get_args());
}
);
preferences:
26.55 ms | 402 KiB | 5 Q