简体   繁体   English

Google Cloud Datastore的PHP API

[英]PHP API for Google Cloud Datastore

I've been unable to locate any documentation for a PHP API for Google Could Datastore. 我一直找不到Google Could Datastore的PHP API的任何文档。 I'm attempting to migrate a NoSQL (MongoDB database) website to Google App Engine - and it appears Cloud Datastore is the best option at present. 我正在尝试将NoSQL(MongoDB数据库)网站迁移到Google App Engine-看来Cloud Datastore是目前的最佳选择。 The only documentation I could locate is for Node.js, Python and Java. 我唯一可以找到的文档是有关Node.js,Python和Java的文档。

https://developers.google.com/datastore/docs/getstarted/ https://developers.google.com/datastore/docs/getstarted/

我在这里有一个用于此的库: https : //github.com/pwhelan/datachore (也可以从packagist以datachore / datachore的形式获得)。

The official PHP client library from Google is now GA. Google的官方PHP客户端库现在为GA。

You can install it using Composer: 您可以使用Composer安装它:

composer require google/cloud

Using it is then as simple as including it, initializing the client for your project, then performing your operations: 然后,使用它就像将其包含在内一样简单,初始化项目的客户端,然后执行操作:

# Includes the autoloader for libraries installed with composer
require __DIR__ . '/vendor/autoload.php';

# Imports the Google Cloud client library
use Google\Cloud\Datastore\DatastoreClient;

# Your Google Cloud Platform project ID
$projectId = 'YOUR_PROJECT_ID';

# Instantiates a client
$datastore = new DatastoreClient([
    'projectId' => $projectId
]);

# The kind for the new entity
$kind = 'Task';

# The name/ID for the new entity
$name = 'sampletask1';

# The Cloud Datastore key for the new entity
$taskKey = $datastore->key($kind, $name);

# Prepares the new entity
$task = $datastore->entity($taskKey, ['description' => 'Buy milk']);

# Saves the entity
$datastore->upsert($task);

echo 'Saved ' . $task->key() . ': ' . $task['description'] . PHP_EOL;

Previous to the official client library, the most widely used PHP library for Cloud Datastore, that's still used and works, is https://github.com/tomwalder/php-gds 在官方客户端库之前,仍在使用和运行的,用于Cloud Datastore的最广泛使用的PHP库是https://github.com/tomwalder/php-gds

As of version 3, PHP GDS supports the v1 REST API meaning you can use it outside of App Engine on any compute service. 从版本3开始,PHP GDS支持v1 REST API,这意味着您可以在任何计算服务的App Engine外部使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM