Datastore/src/V1/Gapic/DatastoreGapicClient.php
public function beginTransaction($projectId, array $optionalArgs = [])
    {
        $request = new BeginTransactionRequest();
        $request->setProjectId($projectId);
        if (isset($optionalArgs['transactionOptions'])) {
            $request->setTransactionOptions($optionalArgs['transactionOptions']);
        }

        $requestParams = new RequestParamsHeaderDescriptor([
          'project_id' => $request->getProjectId(),
        ]);
        $optionalArgs['headers'] = isset($optionalArgs['headers'])
            ? array_merge($requestParams->getHeader(), $optionalArgs['headers'])
            : $requestParams->getHeader();

        return $this->startCall(
            'BeginTransaction',
            BeginTransactionResponse::class,
            $optionalArgs,
            $request
        )->wait();
    }
public function beginTransaction($projectId, array $optionalArgs = [])
    {
        $request = new BeginTransactionRequest();
        $request->setProjectId($projectId);
        if (isset($optionalArgs['transactionOptions'])) {
            $request->setTransactionOptions($optionalArgs['transactionOptions']);
        }

        $requestParams = new RequestParamsHeaderDescriptor([
          'project_id' => $request->getProjectId(),
        ]);
        $optionalArgs['headers'] = isset($optionalArgs['headers'])
            ? array_merge($requestParams->getHeader(), $optionalArgs['headers'])
            : $requestParams->getHeader();

        return $this->startCall(
            'BeginTransaction',
            BeginTransactionResponse::class,
            $optionalArgs,
            $request
        )->wait();
    }
public function beginTransaction ( $ projectId , array $ optionalArgs = [ ] ) { $ request = new BeginTransactionRequest ( ) ; $ request -> setProjectId ( $ projectId ) ; if ( isset ( $ optionalArgs [ 'transactionOptions' ] ) ) { $ request -> setTransactionOptions ( $ optionalArgs [ 'transactionOptions' ] ) ; } $ requestParams = new RequestParamsHeaderDescriptor ( [ 'project_id' => $ request -> getProjectId ( ) , ] ) ; $ optionalArgs [ 'headers' ] = isset ( $ optionalArgs [ 'headers' ] ) ? array_merge ( $ requestParams -> getHeader ( ) , $ optionalArgs [ 'headers' ] ) : $ requestParams -> getHeader ( ) ; return $ this -> startCall ( 'BeginTransaction' , BeginTransactionResponse :: class , $ optionalArgs , $ request ) -> wait ( ) ; }
Begins a new transaction.

Sample code:
```
$datastoreClient = new DatastoreClient();
try {
$projectId = '';
$response = $datastoreClient->beginTransaction($projectId);
} finally {
$datastoreClient->close();
}
```

@param string $projectId    The ID of the project against which to make the request.
@param array  $optionalArgs {
Optional.

@type TransactionOptions $transactionOptions
Options for a new transaction.
@type RetrySettings|array $retrySettings
Retry settings to use for this call. Can be a
{@see Google\ApiCore\RetrySettings} object, or an associative array
of retry settings parameters. See the documentation on
{@see Google\ApiCore\RetrySettings} for example usage.
}

@return \Google\Cloud\Datastore\V1\BeginTransactionResponse

@throws ApiException if the remote call fails
@experimental
Begins a new transaction .