Cloud Datastore Client - Class ReadOnlyTransaction (1.28.2)

Reference documentation and code samples for the Cloud Datastore Client class ReadOnlyTransaction.

Represents a Read-Only Cloud Datastore Transaction.

Read-Only Transactions allow you to execute one or more reads at the current,consistent state of Cloud Datastore at the time the transaction started.

Read-Only Transactions in Google Cloud PHP support rollback operations, butdo not support commit. It should be considered best practice to rollbackread-only transactions when you have finished using them.

Transactions are anoptional feature of Google Cloud Datastore. Queries,lookups and mutations can be executed outside of a Transaction fromGoogle\Cloud\Datastore\DatastoreClient.

Example:

use Google\Cloud\Datastore\DatastoreClient;$datastore = new DatastoreClient();$transaction = $datastore->readOnlyTransaction();
// Read-Only Transactions should be rolled back when they are no longer needed.$key = $datastore->key('Users', 'Bob');$userData = $transaction->lookup($key);$transaction->rollback();

Namespace

Google \ Cloud \ Datastore

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-01-24 UTC.