PHP-DB
PHP-DB copied to clipboard
FETCH_KEY_PAIR / FETCH_UNIQUE / FETCH_GROUP fetch modes
In writing framework benchmark, one of the test cases required data that would have been more conveniently fetched using the FETCH_KEY_PAIR mode. I worked around it by using array_column.
It would be more convenient to either specify the fetch mode as an optional parameter to select or have additional methods (like selectColumn).
public static function fortunes(App $app) {
$fortunes = Controller::getDb()->select(
'SELECT * FROM Fortune'
);
$fortunes = array_column($fortunes, 'message', 'id');
$fortunes[0] = 'Additional fortune added at request time.';
asort($fortunes);
echo $app->view('fortunes.html.twig', ['fortunes' => $fortunes]);
}
benchmark code: https://github.com/bfinlay/FrameworkBenchmarks/blob/delight.im/frameworks/PHP/delight.im/app/Controller.php