NOTE: This repository is part of Google Cloud PHP. Any
support requests, bug reports, or development contributions should be directed to
that project.
A NoSQL document database built for automatic scaling, high performance, and
ease of application development. While the Cloud Datastore interface has many of
the same features as traditional databases, as a NoSQL database it differs from
them in the way it describes relationships between data objects.
Installation
To begin, install the preferred dependency manager for PHP, Composer.
Now install this component:
$ composer require google/cloud-datastore
Authentication
Please see our Authentication guide for more information
on authenticating your client. Once authenticated, you'll be ready to start making requests.
Sample
require 'vendor/autoload.php';
use Google\Cloud\Datastore\DatastoreClient;
$datastore = new DatastoreClient();
// Create an entity
$bob = $datastore->entity('Person');
$bob['firstName'] = 'Bob';
$bob['email'] = 'bob@example.com';
$datastore->insert($bob);
// Update the entity
$bob['email'] = 'bobV2@example.com';
$datastore->update($bob);
// If you know the ID of the entity, you can look it up
$key = $datastore->key('Person', '12345328897844');
$entity = $datastore->lookup($key);
Debugging
Please see our Debugging guide
for more information about the debugging tools.
Version
This component is considered GA (generally available). As such, it will not introduce backwards-incompatible changes in
any minor or patch releases. We will address issues and requests with the highest priority.
Compatibility with Google App Engine
This component is compatible with PHP projects on Google App Engine in the Standard or Flexible environments. To maximize the performance of datastore operations in your app, we recommend the following configuration:
PHP 7 runtime
Enable grpc.so and protobuf.so in your php.ini file
Set your DatastoreClient object's 'transport' option to 'grpc'
You are likely to experience less optimal datastore performance using the PHP 5 runtime on App Engine standard due to the lack of the protobuf extension.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["Version latestkeyboard_arrow_down\n\n- [1.33.1 (latest)](/php/docs/reference/cloud-datastore/latest)\n- [1.33.0](/php/docs/reference/cloud-datastore/1.33.0)\n- [1.32.3](/php/docs/reference/cloud-datastore/1.32.3)\n- [1.31.0](/php/docs/reference/cloud-datastore/1.31.0)\n- [1.30.0](/php/docs/reference/cloud-datastore/1.30.0)\n- [1.29.2](/php/docs/reference/cloud-datastore/1.29.2)\n- [1.28.2](/php/docs/reference/cloud-datastore/1.28.2)\n- [1.26.0](/php/docs/reference/cloud-datastore/1.26.0)\n- [1.25.0](/php/docs/reference/cloud-datastore/1.25.0)\n- [1.24.4](/php/docs/reference/cloud-datastore/1.24.4)\n- [1.23.0](/php/docs/reference/cloud-datastore/1.23.0)\n- [1.22.1](/php/docs/reference/cloud-datastore/1.22.1)\n- [1.21.2](/php/docs/reference/cloud-datastore/1.21.2)\n- [1.19.0](/php/docs/reference/cloud-datastore/1.19.0)\n- [1.18.1](/php/docs/reference/cloud-datastore/1.18.1)\n- [1.17.1](/php/docs/reference/cloud-datastore/1.17.1) \n\nGoogle Cloud PHP Datastore\n==========================\n\n\u003e Idiomatic PHP client for [Cloud Datastore](https://cloud.google.com/datastore/).\n\n[](https://packagist.org/packages/google/cloud-datastore) [](https://packagist.org/packages/google/cloud-datastore)\n\n**NOTE:** This repository is part of [Google Cloud PHP](https://github.com/googleapis/google-cloud-php). Any\nsupport requests, bug reports, or development contributions should be directed to\nthat project.\n\nA NoSQL document database built for automatic scaling, high performance, and\nease of application development. While the Cloud Datastore interface has many of\nthe same features as traditional databases, as a NoSQL database it differs from\nthem in the way it describes relationships between data objects.\n\n### Installation\n\nTo begin, install the preferred dependency manager for PHP, [Composer](https://getcomposer.org/).\n\nNow install this component: \n\n $ composer require google/cloud-datastore\n\n### Authentication\n\nPlease see our [Authentication guide](https://github.com/googleapis/google-cloud-php/blob/main/AUTHENTICATION.md) for more information\non authenticating your client. Once authenticated, you'll be ready to start making requests.\n\n### Sample\n\n require 'vendor/autoload.php';\n\n use Google\\Cloud\\Datastore\\DatastoreClient;\n\n $datastore = new DatastoreClient();\n\n // Create an entity\n $bob = $datastore-\u003eentity('Person');\n $bob['firstName'] = 'Bob';\n $bob['email'] = 'bob@example.com';\n $datastore-\u003einsert($bob);\n\n // Update the entity\n $bob['email'] = 'bobV2@example.com';\n $datastore-\u003eupdate($bob);\n\n // If you know the ID of the entity, you can look it up\n $key = $datastore-\u003ekey('Person', '12345328897844');\n $entity = $datastore-\u003elookup($key);\n\n### Debugging\n\nPlease see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md)\nfor more information about the debugging tools.\n\n### Version\n\nThis component is considered GA (generally available). As such, it will not introduce backwards-incompatible changes in\nany minor or patch releases. We will address issues and requests with the highest priority.\n\n### Compatibility with Google App Engine\n\nThis component is compatible with PHP projects on Google App Engine in the Standard or Flexible environments. To maximize the performance of datastore operations in your app, we recommend the following configuration:\n\n1. PHP 7 runtime\n2. Enable grpc.so and protobuf.so in your php.ini file\n3. Set your DatastoreClient object's 'transport' option to 'grpc'\n\nYou are likely to experience less optimal datastore performance using the PHP 5 runtime on App Engine standard due to the lack of the protobuf extension.\n\n### Next Steps\n\n1. Understand the [official documentation](https://cloud.google.com/datastore/docs/).\n2. Take a look at [in-depth usage samples](https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/datastore)."]]