$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 |
/** * Returns the generation expression for virtual columns * * @param string $column name of the column * * @return array|boolean associative array of column name and their expressions * or false on failure */ public function getColumnGenerationExpression($column = null) { $serverType = Util::getServerType(); if ($serverType == 'MySQL' && PMA_MYSQL_INT_VERSION > 50705 && !$GLOBALS['cfg']['Server']['DisableIS']) { $sql = "SELECT\n `COLUMN_NAME` AS `Field`,\n `GENERATION_EXPRESSION` AS `Expression`\n FROM\n `information_schema`.`COLUMNS`\n WHERE\n `TABLE_SCHEMA` = '" . Util::sqlAddSlashes($this->_db_name) . "'\n AND `TABLE_NAME` = '" . Util::sqlAddSlashes($this->_name) . "'"; if ($column != null) { $sql .= " AND `COLUMN_NAME` = '" . Util::sqlAddSlashes($column) . "'"; } $columns = $this->_dbi->fetchResult($sql, 'Field', 'Expression'); return $columns; } $createTable = $this->showCreate(); if (!$createTable) { return false; } $parser = new Parser($createTable); /** * @var \SqlParser\Statements\CreateStatement $stmt */ $stmt = $parser->statements[0]; $fields = Table::getFields($stmt); if ($column != null) { $expression = isset($fields[$column]['expr']) ? substr($fields[$column]['expr'], 1, -1) : ''; return array($column => $expression); } $ret = array(); foreach ($fields as $field => $options) { if (isset($options['expr'])) { $ret[$field] = substr($options['expr'], 1, -1); } } return $ret; }