$sql = 'SELECT * FROM user';
$users = $GLOBALS['dbi']->fetchResult($sql);
produces
$users[] = array('id' => 123, 'name' => 'John Doe')
$sql = 'SELECT id, name FROM user';
$users = $GLOBALS['dbi']->fetchResult($sql, 'id');
produces
$users['123'] = array('id' => 123, 'name' => 'John Doe')
$sql = 'SELECT id, name FROM user';
$users = $GLOBALS['dbi']->fetchResult($sql, 0);
produces
$users['123'] = array(0 => 123, 1 => 'John Doe')
$sql = 'SELECT id, name FROM user';
$users = $GLOBALS['dbi']->fetchResult($sql, 'id', 'name');
or
$users = $GLOBALS['dbi']->fetchResult($sql, 0, 1);
produces
$users['123'] = 'John Doe'
$sql = 'SELECT name FROM user';
$users = $GLOBALS['dbi']->fetchResult($sql);
produces
$users[] = 'John Doe'
$sql = 'SELECT group, name FROM user'
$users = $GLOBALS['dbi']->fetchResult($sql, array('group', null), 'name');
produces
$users['admin'][] = 'John Doe'
$sql = 'SELECT group, name FROM user'
$users = $GLOBALS['dbi']->fetchResult($sql, array('group', 'name'), 'id');
produces
$users['admin']['John Doe'] = '123'
public fetchResult ( string $query, string | integer | array $key = null, string | integer $value = null, object $link = null, integer $options ) : array | ||
$query | string | query to execute |
$key | string | integer | array | field-name or offset used as key for array or array of those |
$value | string | integer | value-name or offset used as value for array |
$link | object | mysql link |
$options | integer | query options |
return | array | resultrows or values indexed by $key |