# Cloud Spanner Client - Class Instance (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 Instance.

Represents a Cloud Spanner instance

Example:

    use Google\Cloud\Spanner\SpannerClient;

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

    $instance = $spanner->instance('my-instance');

## Namespace

Google \\ Cloud \\ Spanner

## Methods

### __construct

Create an object representing a Cloud Spanner instance.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `spannerClient` | `https://docs.cloud.google.com/php/docs/reference/cloud-spanner/latest/V1.Client.SpannerClient` The spanner client. |
| `instanceAdminClient` | `https://docs.cloud.google.com/php/docs/reference/cloud-spanner/latest/Admin.Instance.V1.Client.InstanceAdminClient` The instance admin client. |
| `databaseAdminClient` | `https://docs.cloud.google.com/php/docs/reference/cloud-spanner/latest/Admin.Database.V1.Client.DatabaseAdminClient` The database admin client. |
| `serializer` | `Serializer` The serializer instance to encode/decode messages. |
| `projectId` | `string` The project ID. |
| `name` | `string` The instance name or ID. |
| `options` | `array` Instance options |
| `↳ directedReadOptions` | `array` Directed read options. [V1\\DirectedReadOptions](https://docs.cloud.google.com/php/docs/reference/cloud-spanner/latest/V1.DirectedReadOptions) If using the `replicaSelection::type` setting, utilize the constants available in [V1\\DirectedReadOptions\\ReplicaSelection\\Type](https://docs.cloud.google.com/php/docs/reference/cloud-spanner/latest/V1.DirectedReadOptions.ReplicaSelection.Type) to set a value. |
| `↳ isolationLevel` | `int` The level of Isolation for the transactions executed by this Client's instance. **Defaults to** IsolationLevel::ISOLATION_LEVEL_UNSPECIFIED |
| `↳ routeToLeader` | `bool` Enable/disable Leader Aware Routing. **Defaults to** `true` (enabled). |
| `↳ returnInt64AsObject` | `bool` If true, 64 bit integers will be returned as a [Google\\Cloud\\Core\\Int64](https://docs.cloud.google.com/php/docs/reference/cloud-core/latest/Int64.html) object for 32 bit platform compatibility. **Defaults to** false. |
| `↳ cacheItemPool` | `CacheItemPool` |
| `↳ instance` | `array` An array representation of the instance object. |

### name

Return the instance name.

Example:

    $name = $instance->name();

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `string` |   |

### info

Return the service representation of the instance.

This method may require a service call.

Example:

    $info = $instance->info();
    echo $info['nodeCount'];

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `options` | `array` Configuration options |
| `↳ fieldMask` | `string|string[]` One or a list of `Instance` fields that should be returned. Eligible values are: `name`, `displayName`, `endpointUris`, `labels`, `config`, `nodeCount`, `state`. If absent, all fields are returned. Note: This parameter will only apply when service call is required (`info` values are not present). |

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

### exists

Check if the instance exists.

This method requires a service call.

Example:

    if ($instance->exists()) {
       echo 'Instance exists!';
    }

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `options` | `array` \[optional\] Configuration options. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `bool` |   |

### reload

See also:

- [GetInstanceRequest](https://cloud.google.com/spanner/reference/rpc/google.spanner.admin.instance.v1#google.spanner.admin.instance.v1.GetInstanceRequest)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `options` | `array` Configuration options |
| `↳ fieldMask` | `string|string[]` One or a list of `Instance` fields that should be returned. Eligible values are: `name`, `displayName`, `endpointUris`, `labels`, `config`, `nodeCount`, `state`. If absent, all fields are returned. |

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

### create

See also:

- [CreateInstanceRequest](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.instance.v1#createinstancerequest)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `config` | `https://docs.cloud.google.com/php/docs/reference/cloud-spanner/latest/InstanceConfiguration` The configuration to use |
| `options` | `array` Configuration options |
| `↳ displayName` | `string` **Defaults to** the value of $name. |
| `↳ nodeCount` | `int` **Defaults to** `1`. |
| `↳ processingUnits` | `int` An alternative measurement to `nodeCount` that allows smaller increments. |
| `↳ labels` | `array` For more information, see [Using labels to organize Google Cloud Platform resources](https://cloudplatform.googleblog.com/2015/10/using-labels-to-organize-Google-Cloud-Platform-resources.html). |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-core/latest/LongRunning.LongRunningOperation.html` |   |

### state

Return the instance state.

When instances are created or updated, they may take some time before
they are ready for use. This method allows for checking whether an
instance is ready. Note that this value is cached within the class instance,
so if you are polling it, first call [Instance::reload()](https://docs.cloud.google.com/php/docs/reference/cloud-spanner/latest/Instance#_Google_Cloud_Spanner_Instance__reload__)
to refresh the cached value

Example:

    if ($instance->state() === Instance::STATE_READY) {
        echo 'Instance is ready!';
    }

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `options` | `array` \[optional\] Configuration options. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `int` |   |

### update

See also:

- [UpdateInstanceRequest](https://cloud.google.com/spanner/reference/rpc/google.spanner.admin.instance.v1#updateinstancerequest)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `options` | `array` Configuration options |
| `↳ displayName` | `string` The descriptive name for this instance as it appears in UIs. **Defaults to** the value of $name. |
| `↳ nodeCount` | `int` The number of nodes allocated to this instance. **Defaults to** `1`. |
| `↳ processingUnits` | `int` An alternative measurement to `nodeCount` that allows smaller increments. |
| `↳ labels` | `array` For more information, see [Using labels to organize Google Cloud Platform resources](https://goo.gl/xmQnxf). |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-core/latest/LongRunning.LongRunningOperation.html` |   |

### delete

See also:

- [DeleteInstanceRequest](https://cloud.google.com/spanner/reference/rpc/google.spanner.admin.instance.v1#deleteinstancerequest)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `options` | `array` \[optional\] Configuration options. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `void` |   |

### createDatabase

See also:

- [CreateDatabaseRequest](https://cloud.google.com/spanner/reference/rpc/google.spanner.admin.database.v1#createdatabaserequest)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `name` | `string` The database name. |
| `options` | `array` Configuration Options |
| `↳ statements` | `array` Additional DDL statements. |
| `↳ protoDescriptors` | `https://protobuf.dev/reference/php/api-docs/Google/Protobuf/FileDescriptorSet|string` The file descriptor set object to be used in the update, or alternatively, an absolute path to the generated file descriptor set. The descriptor set is only used during DDL statements, such as `CREATE PROTO BUNDLE`. |
| `↳ sessionPool` | `SessionPoolInterface` A pool used to manage sessions. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-core/latest/LongRunning.LongRunningOperation.html` |   |

### createDatabaseFromBackup

Create a database from a backup.

Example:

    $operation = $instance->createDatabaseFromBackup('my-new-database', $backup);

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `name` | `string` The database name. |
| `backup` | `https://docs.cloud.google.com/php/docs/reference/cloud-spanner/latest/Backup|string` The backup to restore, given as a Backup instance or a string of the form `projects/<project>/instances/<instance>/backups/<backup>`. |
| `options` | `array` \[optional\] Configuration options. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-core/latest/LongRunning.LongRunningOperation.html` |   |

### database

Lazily instantiate a database object

Example:

    $database = $instance->database('my-database');

Database role configured on the database object
will be applied to the session created by this object.

    $database = $instance->database('my-database', ['databaseRole' => 'Reader']);

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `name` | `string` The database name |
| `options` | `array` Configuration options. |
| `↳ routeToLeader` | `bool` Enable/disable Leader Aware Routing. **Defaults to** `true` (enabled). |
| `↳ defaultQueryOptions` | `array` |
| `↳ returnInt64AsObject` | `bool` If true, 64 bit integers will be returned as a [Google\\Cloud\\Core\\Int64](https://docs.cloud.google.com/php/docs/reference/cloud-core/latest/Int64.html) object for 32 bit platform compatibility. **Defaults to** false. |
| `↳ databaseRole` | `string` The user created database role which creates the session. |
| `↳ database` | `array` The database info. |
| `↳ session` | `Session\SessionCache` |
| `↳ lock` | `https://docs.cloud.google.com/php/docs/reference/cloud-core/latest/Lock.LockInterface.html` |
| `↳ isolationLevel` | `int` The IsolationLevel set for the transaction. Check [V1\\TransactionOptions\\IsolationLevel](https://docs.cloud.google.com/php/docs/reference/cloud-spanner/latest/V1.TransactionOptions.IsolationLevel) for more details. |

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

### databases

See also:

- [ListDatabasesRequest](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.database.v1#listdatabasesrequest)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `options` | `array` Configuration options. |
| `↳ pageSize` | `int` Maximum number of results to return per request. |
| `↳ resultLimit` | `int` Limit the number of results returned in total. **Defaults to** `0` (return all results). |
| `↳ pageToken` | `string` A previously-returned page token used to resume the loading of results from a specific point. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-core/latest/Iterator.ItemIterator.html<https://docs.cloud.google.com/php/docs/reference/cloud-spanner/latest/Database>` |   |

### backup

Lazily instantiate a backup object

Example:

    $backup = $instance->backup('my-backup');

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `name` | `string` The backup name. |
| `backup` | `array` |

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

### backups

See also:

- [ListBackupsRequest](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.database.v1#listbackupsrequest)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `options` | `array` Configuration options. |
| `↳ filter` | `string` The standard list filter. |
| `↳ pageSize` | `int` The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved. |
| `↳ resultLimit` | `int` Limit the number of results returned in total. **Defaults to** `0` (return all results). |
| `↳ pageToken` | `string` A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-core/latest/Iterator.ItemIterator.html<https://docs.cloud.google.com/php/docs/reference/cloud-spanner/latest/Backup>` |   |

### backupOperations

Lists backup operations for the instance.

Example:

    $backupOperations = $instance->backupOperations();

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `options` | `array` Configuration options. |
| `↳ pageSize` | `int` The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved. |
| `↳ resultLimit` | `int` Limit the number of results returned in total. **Defaults to** `0` (return all results). |
| `↳ pageToken` | `string` A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-core/latest/Iterator.ItemIterator.html<https://docs.cloud.google.com/php/docs/reference/cloud-core/latest/LongRunning.LongRunningOperation.html>` |   |

### databaseOperations

Lists database operations for the instance.

Example:

    $databaseOperations = $instance->databaseOperations();

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `options` | `array` Configuration options. |
| `↳ pageSize` | `int` The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved. |
| `↳ resultLimit` | `int` Limit the number of results returned in total. **Defaults to** `0` (return all results). |
| `↳ pageToken` | `string` A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-core/latest/Iterator.ItemIterator.html<https://docs.cloud.google.com/php/docs/reference/cloud-core/latest/LongRunning.LongRunningOperation.html>` |   |

### iam

Manage the instance IAM policy

Example:

    $iam = $instance->iam();

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `Google\Cloud\Core\Iam\IamManager` |   |

### directedReadOptions

Return the directed read options.

Example:

    $name = $instance->directedReadOptions();

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

### resumeOperation

Resume a Long Running Operation

Example:

    $operation = $instance->resumeOperation($operationName);

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `operationName` | `string` The Long Running Operation name. |
| `options` | `array` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-core/latest/LongRunning.LongRunningOperation.html` |   |

### longRunningOperations

List long running operations.

Example:

    $operations = $instance->longRunningOperations();

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `options` | `array` Configuration Options. |
| `↳ name` | `string` The name of the operation collection. |
| `↳ filter` | `string` The standard list filter. |
| `↳ pageSize` | `int` Maximum number of results to return per request. |
| `↳ resultLimit` | `int` Limit the number of results returned in total. **Defaults to** `0` (return all results). |
| `↳ pageToken` | `string` A previously-returned page token used to resume the loading of results from a specific point. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-core/latest/Iterator.ItemIterator.html<https://docs.cloud.google.com/php/docs/reference/cloud-core/latest/LongRunning.LongRunningOperation.html>` |   |

### __debugInfo

Represent the class in a more readable and digestable fashion.

## Constants

### STATE_READY

    Value: \Google\Cloud\Spanner\Admin\Instance\V1\Instance\State::READY

### STATE_CREATING

    Value: \Google\Cloud\Spanner\Admin\Instance\V1\Instance\State::CREATING

### DEFAULT_NODE_COUNT

    Value: 1