You are here

public function DatabaseStatement_sqlsrv::fetchAllKeyed in Drupal driver for SQL Server and SQL Azure 7.3

Same name and namespace in other branches
  1. 7.2 sqlsrv/database.inc \DatabaseStatement_sqlsrv::fetchAllKeyed()

Experimental, do not iterate if not needed.

Parameters

mixed $key_index:

mixed $value_index:

Return value

array|DatabaseStatement_sqlsrv

Overrides DatabaseStatementBase::fetchAllKeyed

File

sqlsrv/database.inc, line 1038
Database interface code for Microsoft SQL Server.

Class

DatabaseStatement_sqlsrv

Code

public function fetchAllKeyed($key_index = 0, $value_index = 1) {

  // If we are asked for the default behaviour, rely
  // on the PDO as being faster.
  if ($key_index == 0 && $value_index == 1 && $this
    ->columnCount() == 2) {
    $this
      ->setFetchMode(PDO::FETCH_KEY_PAIR);
    return $this
      ->fetchAll();
  }

  // We need to do this manually.
  $return = array();
  $this
    ->setFetchMode(PDO::FETCH_NUM);
  foreach ($this as $record) {
    $return[$record[$key_index]] = $record[$value_index];
  }
  return $return;
}