- 2.0.1-RC1 (latest)
- 2.0.0-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 SpannerClient.
Cloud Spanner is a highly scalable, transactional, managed, NewSQL database service. Find more information at Cloud Spanner docs.
In production environments, it is highly recommended that you make use of the Protobuf PHP extension for improved performance. Protobuf can be installed via PECL.
$ pecl install protobuf Example:
use Google\Cloud\Spanner\SpannerClient; $spanner = new SpannerClient(); // Using a Spanner Emulator use Google\Cloud\Spanner\SpannerClient; // Be sure to use the port specified when starting the emulator. // `9010` is used as an example only. putenv('SPANNER_EMULATOR_HOST=localhost:9010'); $spanner = new SpannerClient(); use Google\Cloud\Spanner\SpannerClient; use Google\Cloud\Spanner\V1\DirectedReadOptions\ReplicaSelection\Type as ReplicaType; $directedOptions = [ 'directedReadOptions' => [ 'includeReplicas' => [ 'replicaSelections' => [ [ 'location' => 'us-central1', 'type' => ReplicaType::READ_WRITE ] ], 'autoFailoverDisabled' => false ] ] ]; $spanner = new SpannerClient($directedOptions); use Google\Cloud\Spanner\SpannerClient; $config = ['routeToLeader' => false]; $spanner = new SpannerClient($config); Namespace
Google \ Cloud \ SpannerMethods
__construct
Create a Spanner client. Please note that this client requires the gRPC extension.
| Parameters | |||||||
|---|---|---|---|---|---|---|---|
| Name | Description | ||||||
| config | arrayConfiguration Options. | ||||||
| ↳ apiEndpoint | stringA hostname with optional port to use in place of the service's default endpoint. | ||||||
| ↳ projectId | stringThe project ID from the Google Developer's Console. | ||||||
| ↳ authCache | CacheItemPoolInterfaceA cache for storing access tokens. Defaults to a simple in memory implementation. | ||||||
| ↳ authCacheOptions | arrayCache configuration options. | ||||||
| ↳ authHttpHandler | callableA handler used to deliver Psr7 requests specifically for authentication. | ||||||
| ↳ credentialsFetcher | FetchAuthTokenInterfaceA credentials fetcher instance. | ||||||
| ↳ httpHandler | callableA handler used to deliver Psr7 requests. Only valid for requests sent over REST. | ||||||
| ↳ keyFile | array[DEPRECATED] @deprecated This option is being deprecated because of a potential security risk. This option does not validate the credential configuration. The security risk occurs when a credential configuration is accepted from a source that is not under your control and used without validation on your side. If you know that you will be loading credential configurations of a specific type, it is recommended to create the credentials directly and configure them using the  | ||||||
| ↳ keyFilePath | string[DEPRECATED] @deprecated This option is being deprecated because of a potential security risk. This option does not validate the credential configuration. The security risk occurs when a credential configuration is accepted from a source that is not under your control and used without validation on your side. If you know that you will be loading credential configurations of a specific type, it is recommended to create the credentials directly and configure them using the  | ||||||
| ↳ requestTimeout | floatSeconds to wait before timing out the request. Defaults to  | ||||||
| ↳ retries | intNumber of retries for a failed request. Used only with default backoff strategy. Defaults to  | ||||||
| ↳ scopes | arrayScopes to be used for the request. | ||||||
| ↳ quotaProject | stringSpecifies a user project to bill for access charges associated with the request. | ||||||
| ↳ returnInt64AsObject | boolIf true, 64 bit integers will be returned as a Google\Cloud\Core\Int64 object for 32 bit platform compatibility. Defaults to false. | ||||||
| ↳ queryOptions | arrayQuery optimizer configuration. 
 | ||||||
| ↳ useDiscreteBackoffs | bool
 | ||||||
| ↳ directedReadOptions | arrayDirected read options. V1\DirectedReadOptions If using the  | ||||||
| ↳ routeToLeader | boolEnable/disable Leader Aware Routing. Defaults to  | ||||||
| ↳ universeDomain | stringThe expected universe of the credentials. Defaults to "googleapis.com" | ||||||
| ↳ isolationLevel | intThe level of Isolation for the transactions executed by this Client's instance. Defaults to IsolationLevel::ISOLATION_LEVEL_UNSPECIFIED | ||||||
batch
Get a Batch Client.
Batch Clients allow you to execute reads of very large data sets, spread across multiple partitions.
Example:
$batch = $spanner->batch('instance-id', 'database-id'); Database role configured in the optional $options array will be applied to the session created by this object.
$batch = $spanner->batch('instance-id', 'database-id', ['databaseRole' => 'Reader']); | Parameters | |
|---|---|
| Name | Description | 
| instanceId | stringThe instance to connect to. | 
| databaseId | stringThe database to connect to. | 
| options | arrayConfiguration options. | 
| ↳ databaseRole | stringThe user created database role which creates the session. | 
| Returns | |
|---|---|
| Type | Description | 
| Batch\BatchClient | |
createInstanceConfiguration
See also:
| Parameters | |
|---|---|
| Name | Description | 
| baseConfig | InstanceConfigurationThe base configuration to extend for this custom instance configuration. | 
| name | stringThe configuration name. Should be prefixed with "custom-". | 
| replicas | array<Admin\Instance\V1\ReplicaInfo>|arrayThe replica information for the new instance configuration. This array must contain all the replicas from the base configuration, plus at least one from list of optional replicas of the base configuration. One of the replicas must be set as the default leader location. | 
| options | arrayConfiguration options. | 
| ↳ displayName | stringDefaults to the value of $name. | 
| ↳ leaderOptions | arrayAllowed values of the "default_leader" schema option for databases in instances that use this instance configuration. Defaults to the leader options of the base configuration. Please note it may be possible for the default value to be an empty array when lazy loading the base configuration. To ensure the default value matches the upstream values please make sure to trigger a network request on the base configuration with either InstanceConfiguration::reload() or InstanceConfiguration::info(). | 
| ↳ labels | arrayFor more information, see Using labels to organize Google Cloud Platform resources. | 
| ↳ validateOnly | boolAn option to validate, but not actually execute, the request, and provide the same response. Defaults to  | 
| Returns | |
|---|---|
| Type | Description | 
| Google\Cloud\Core\LongRunning\LongRunningOperation<InstanceConfiguration> | |
instanceConfigurations
See also:
| Parameters | |
|---|---|
| Name | Description | 
| options | arrayConfiguration Options. | 
| ↳ pageSize | intMaximum number of results to return per request. | 
| ↳ resultLimit | intLimit the number of results returned in total. Defaults to  | 
| ↳ pageToken | stringA previously-returned page token used to resume the loading of results from a specific point. | 
| Returns | |
|---|---|
| Type | Description | 
| Google\Cloud\Core\Iterator\ItemIterator<InstanceConfiguration> | |
instanceConfiguration
See also:
| Parameters | |
|---|---|
| Name | Description | 
| name | stringThe Configuration name. | 
| options | array | 
| Returns | |
|---|---|
| Type | Description | 
| InstanceConfiguration | |
instanceConfigOperations
Lists instance configuration operations for the project.
Example:
$instanceConfigOperations = $spanner->instanceConfigOperations(); | Parameters | |
|---|---|
| Name | Description | 
| options | arrayConfiguration options. | 
| ↳ pageSize | intThe 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 | intLimit the number of results returned in total. Defaults to  | 
| ↳ pageToken | stringA 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 | 
| Google\Cloud\Core\Iterator\ItemIterator<Google\Cloud\Core\LongRunning\LongRunningOperation> | |
createInstance
See also:
| Parameters | |
|---|---|
| Name | Description | 
| config | InstanceConfigurationThe configuration to use | 
| name | stringThe instance name | 
| options | arrayConfiguration options | 
| ↳ displayName | stringDefaults to the value of $name. | 
| ↳ nodeCount | intDefaults to  | 
| ↳ labels | arrayFor more information, see Using labels to organize Google Cloud Platform resources. | 
| Returns | |
|---|---|
| Type | Description | 
| Google\Cloud\Core\LongRunning\LongRunningOperation<Instance> | |
instance
Lazily instantiate an instance.
Example:
$instance = $spanner->instance('my-instance'); | Parameters | |
|---|---|
| Name | Description | 
| name | stringThe instance name | 
| instance | array | 
| Returns | |
|---|---|
| Type | Description | 
| Instance | |
instances
See also:
| Parameters | |
|---|---|
| Name | Description | 
| options | arrayConfiguration options | 
| ↳ filter | stringAn expression for filtering the results of the request. | 
| ↳ pageSize | intMaximum number of results to return per request. | 
| ↳ resultLimit | intLimit the number of results returned in total. Defaults to  | 
| ↳ pageToken | stringA previously-returned page token used to resume the loading of results from a specific point. | 
| Returns | |
|---|---|
| Type | Description | 
| Google\Cloud\Core\Iterator\ItemIterator<Instance> | |
connect
Connect to a database to run queries or mutations.
Example:
$database = $spanner->connect('instance-id', 'database-id'); Database role configured on the $options parameter will be applied to the session created by this object. Note: When the databseRole and sessionPool both are present in the options, we prioritize the sessionPool.
$database = $spanner->connect('instance-id', 'database-id', ['databaseRole' => 'Reader']); | Parameters | |
|---|---|
| Name | Description | 
| instance | Instance|stringThe instance object or instance name. | 
| name | stringThe database name. | 
| options | arrayConfiguration options. | 
| ↳ sessionPool | SessionPoolInterfaceA pool used to manage sessions. | 
| ↳ databaseRole | stringThe user created database role which creates the session. | 
| Returns | |
|---|---|
| Type | Description | 
| Database | |
keySet
Create a new KeySet object
Example:
$keySet = $spanner->keySet(); // Create a keyset to return all rows in a table. $keySet = $spanner->keySet(['all' => true]); | Parameters | |
|---|---|
| Name | Description | 
| options | arrayConfiguration Options | 
| ↳ keys | arrayA list of keys | 
| ↳ ranges | KeyRange[]A list of key ranges | 
| ↳ all | boolWhether to include all keys in a table | 
| Returns | |
|---|---|
| Type | Description | 
| KeySet | |
keyRange
Create a new KeyRange object
Example:
$range = $spanner->keyRange(); // Ranges can be created with all data supplied. $range = $spanner->keyRange([ 'startType' => KeyRange::TYPE_OPEN, 'start' => ['Bob'], 'endType' => KeyRange::TYPE_OPEN, 'end' => ['Jill'] ]); | Parameters | |
|---|---|
| Name | Description | 
| options | arrayConfiguration Options. | 
| ↳ startType | stringEither "open" or "closed". Use constants  | 
| ↳ start | arrayThe key with which to start the range. | 
| ↳ endType | stringEither "open" or "closed". Use constants  | 
| ↳ end | arrayThe key with which to end the range. | 
| Returns | |
|---|---|
| Type | Description | 
| KeyRange | |
bytes
Create a Bytes object.
Example:
$bytes = $spanner->bytes('hello world'); | Parameter | |
|---|---|
| Name | Description | 
| bytes | Psr\Http\StreamInterface|string|resourceThe bytes value. | 
| Returns | |
|---|---|
| Type | Description | 
| Bytes | |
date
Create a Date object.
Example:
$date = $spanner->date(new \DateTime('1995-02-04')); | Parameter | |
|---|---|
| Name | Description | 
| date | DateTimeInterfaceThe date value. | 
| Returns | |
|---|---|
| Type | Description | 
| Date | |
timestamp
Create a Timestamp object.
Example:
$timestamp = $spanner->timestamp(new \DateTime('2003-02-05 11:15:02.421827Z')); | Parameters | |
|---|---|
| Name | Description | 
| timestamp | DateTimeInterfaceThe timestamp value. | 
| nanoSeconds | int[optional] The number of nanoseconds in the timestamp. | 
| Returns | |
|---|---|
| Type | Description | 
| Timestamp | |
numeric
Create a Numeric object.
Numeric represents a value with a data type of Numeric.
It supports a fixed 38 decimal digits of precision and 9 decimal digits of scale, and values are in the range of -99999999999999999999999999999.999999999 to 99999999999999999999999999999.999999999.
Example:
$numeric = $spanner->numeric('99999999999999999999999999999999999999.999999999'); | Parameter | |
|---|---|
| Name | Description | 
| value | string|int|floatThe Numeric value. | 
| Returns | |
|---|---|
| Type | Description | 
| numeric | |
pgNumeric
Represents a value with a data type of PG Numeric for the Postgres Dialect database.
It supports a value precision of up to 131072 digits before the decimal point and up to 16383 digits after the decimal point.
Example:
$pgNumeric = $spanner->pgNumeric('99999999999999999999999999999999999999.000000999999999'); | Parameter | |
|---|---|
| Name | Description | 
| value | string|int|float|nullThe PgNumeric value. | 
| Returns | |
|---|---|
| Type | Description | 
| PgNumeric | |
pgJsonb
Represents a value with a data type of PG JSONB for the Postgres Dialect database.
Example:
$pgJsonb = $spanner->pgJsonb('}'); | Parameter | |
|---|---|
| Name | Description | 
| value | mixed | 
pgOid
Represents a value with a data type of PG OID for the Postgres Dialect database.
Example:
$pgOid = $spanner->pgOid('123'); | Parameter | |
|---|---|
| Name | Description | 
| value | mixed | 
int64
Create an Int64 object. This can be used to work with 64 bit integers as a string value while on a 32 bit platform.
Example:
$int64 = $spanner->int64('9223372036854775807'); | Parameter | |
|---|---|
| Name | Description | 
| value | string | 
| Returns | |
|---|---|
| Type | Description | 
| Google\Cloud\Core\Int64 | |
duration
Create a Duration object.
Example:
$duration = $spanner->duration(100, 00001); | Parameters | |
|---|---|
| Name | Description | 
| seconds | intThe number of seconds in the duration. | 
| nanos | int[optional] The number of nanoseconds in the duration. Defaults to*  | 
| Returns | |
|---|---|
| Type | Description | 
| Duration | |
commitTimestamp
Create a CommitTimestamp object.
Commit Timestamps may be used to implement server-side commit timestamp tracking in tables. Refer to CommitTimestamp for usage details.
Example:
$commitTimestamp = $spanner->commitTimestamp(); | Returns | |
|---|---|
| Type | Description | 
| CommitTimestamp | |
resumeOperation
{ Resume a Long Running Operation
| Returns | |
|---|---|
| Type | Description | 
| void | |
Constants
VERSION
Value: '1.106.0'FULL_CONTROL_SCOPE
Value: 'https://www.googleapis.com/auth/spanner.data'ADMIN_SCOPE
Value: 'https://www.googleapis.com/auth/spanner.admin'