XDB improvements.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sat, 27 Dec 2008 23:09:06 +0000 (00:09 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sat, 27 Dec 2008 23:09:06 +0000 (00:09 +0100)
commite4f6c7d0410bdc8c0f62abc4ee17092dbc52126c
tree2d5476470e58a29978354db636f7b9d6df1f5b4f
parentf76b8d9256f204875d91100341e6a6249bda15ce
XDB improvements.

Added methods to XDB namespace:
* XDB::fetchOne(Row|Assoc|Cell)
* XDB::fetchAll(Row|Assoc)
* XDB::fetchColumn

fetchAll(Row|Assoc) now take 2 optional arguments:
* a column to use as the as the key of the returned object
* a flag telling whether we allow simplification of the returned array if a key is defined and only one other column remain

e.g.:
$fids = XDB::fetchAllAssoc('name', 'SELECT fid, name FROM forums');
-> array('xorg.general' => '1', 'xorg.promo.x2003' => '2', ...)

$fids = XDB::fetchAllAssoc('name', true, 'SELECT fid, name FROM forums');
-> array('xorg.general' => array('fid' => '1'),
         'xorg.promo.x2003' => array('fid => '2'), ...)

$fnames = XDB::fetchAllAssoc('fid', 'SELECT fid, name FROM forums');
-> array('1' => 'xorg.general', '2' => 'xorg.promo.2003', ...);

$f = XDB::fetchAllAssoc('SELECT fid, name FROM forums');
-> array(array('fid' => '1', 'name' => 'xorg.general'),
         array('fid' => '2', 'name' => 'xorg.promo.x2003'),
         ...)

Note: Optional arguments given to XDB::fetch... MUST be given before the
query.

Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
classes/xdb.php