# Cloud Spanner Client - Class Result (2.9.0)

2.9.0 (latest) 2.8.1 2.7.0 2.6.1 2.5.1 2.4.1 2.3.0 2.2.0 2.1.0 2.0.1-RC1 1.106.0 1.105.1 1.104.1 1.103.0 1.102.0 1.101.0 1.100.0 1.98.0 1.97.0 1.96.0 1.95.0 1.94.0 1.93.1 1.92.1 1.91.0 1.90.0 1.89.0 1.88.0 1.87.0 1.86.0 1.85.0 1.84.0 1.83.0 1.82.0 1.81.0 1.80.0 1.79.0 1.78.0 1.77.0 1.76.1 1.68.0 1.67.0 1.66.0 1.65.0 1.64.0 1.63.2 1.62.1 1.61.0 1.60.0 1.59.0 1.58.4 1.57.0 1.56.0 1.55.0 1.54.2 Reference documentation and code samples for the Cloud Spanner Client class Result.

Represent a Cloud Spanner lookup result (either read or executeSql).

Example:

    use Google\Cloud\Spanner\SpannerClient;

    $spanner = new SpannerClient(['projectId' => 'my-project']);

    $database = $spanner->connect('my-instance', 'my-database');
    $result = $database->execute('SELECT * FROM Posts');

## Namespace

Google \\ Cloud \\ Spanner

## Methods

### __construct

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `operation` | `Operation` Runs operations against Google Cloud Spanner. |
| `session` | `Session\SessionCache` The session used for any operations executed. |
| `call` | `callable` A callable, yielding a generator filled with results. |
| `transactionContext` | `string` The transaction's context. |
| `mapper` | `https://docs.cloud.google.com/php/docs/reference/cloud-spanner/latest/ValueMapper` Maps values. |
| `retrySettings` | `https://docs.cloud.google.com/php/docs/reference/gax/latest/RetrySettings.html|null` Retry configuration options. Currently, only the `maxRetries` option is supported. |
| `↳ maxRetries` | `int` The maximum number of retry attempts before the operation fails. Defaults to 3. |

### rows

Return the formatted and decoded rows. If the stream is interrupted and
a resume token is available, attempts will be made on your behalf to
resume.

Example:

    $rows = $result->rows();

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `format` | `string` Determines the format in which rows are returned. `Result::RETURN_NAME_VALUE_PAIR` returns items as a multi-dimensional array containing a name and a value key. Ex: `[0 => ['name' => 'column1', 'value' => 'my_value']]`. `Result::RETURN_ASSOCIATIVE` returns items as an associative array with the column name as the key. Please note with this option, if duplicate column names are present a `\RuntimeException` will be thrown. `Result::RETURN_ZERO_INDEXED` returns items as a 0 indexed array, with the key representing the column number as found by executing [Result::columns()](https://docs.cloud.google.com/php/docs/reference/cloud-spanner/latest/Result#_Google_Cloud_Spanner_Result__columns__). Ex: `[0 => 'my_value']`. **Defaults to** `Result::RETURN_ASSOCIATIVE`. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `Generator` |   |

### columns

Return column names.

Will be populated once the result set is iterated upon.

Example:

    $columns = $result->columns();

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `array|null` |   |

### metadata

Return result metadata.

Will be populated once the result set is iterated upon.

Example:

    $metadata = $result->metadata();

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `array|null` | \[ResultSetMetadata\](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.ResultSetMetadata). |

### session

Return the session associated with the result stream.

Example:

    $session = $result->session();

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `Session\SessionCache` |   |

### stats

Get the query plan and execution statistics for the query that produced
this result set.

By default, statistics are returned by default only when executing a DML
statement. To receive statistics for a SELECT statement, set
`$options.queryMode` to `Result::MODE_PROFILE`, as demonstrated below.

Setting `$options.queryMode` to `Result::MODE_PLAN` will return the query
plan without any results or execution statistics information.

Example:

    $stats = $result->stats();

    // Executing a query with stats returned.
    use Google\Cloud\Spanner\Result;

    $res = $database->execute('SELECT * FROM Posts', [
        'queryMode' => Result::MODE_PROFILE
    ]);

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `array|null` | \[ResultSetStats\](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.ResultSetStats). |

### snapshot

Returns a snapshot which was begun in the read or execute, if one exists.

Will be populated once the result set is iterated upon.

Example:

    $snapshot = $result->snapshot();

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `TransactionalReadInterface|null` |   |

### transaction

Returns a transaction which was begun in the read or execute, if one exists.

Will be populated once the result set is iterated upon.

Example:

    $transaction = $result->transaction();

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-spanner/latest/Transaction|null` |   |

### getIterator

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `Generator` |   |

## Constants

### RETURN_NAME_VALUE_PAIR

    Value: 'nameValuePair'

### RETURN_ASSOCIATIVE

    Value: 'associative'

### RETURN_ZERO_INDEXED

    Value: 'zeroIndexed'

### MODE_NORMAL

    Value: \Google\Cloud\Spanner\V1\ExecuteSqlRequest\QueryMode::NORMAL

### MODE_PLAN

    Value: \Google\Cloud\Spanner\V1\ExecuteSqlRequest\QueryMode::PLAN

### MODE_PROFILE

    Value: \Google\Cloud\Spanner\V1\ExecuteSqlRequest\QueryMode::PROFILE