1

我一直无法找到Google Could Datastore的PHP API的任何文档。我正在尝试将NoSQL(MongoDB数据库)网站迁移到Google App Engine--目前,云数据存储似乎是最佳选择。我能找到的唯一文档是用于Node.js,Python和Java。Google Cloud Datastore的PHP API

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

+1

https://developers.google.com/appengine/docs/php/gettingstarted/introduction? – 2013-07-05 03:14:14

+0

是的,我看了一下 - 但没有API参考:Stuart说很快就会有一些东西可用:https://twitter.com/TheFuriousAnt/status/353103115647598592 –

+0

同时,您可以使用API​​客户端:https:/ /code.google.com/p/google-api-php-client/ – Mars

回答

0

Google的official PHP client library现在是GA。

您可以用作曲安装:

composer require google/cloud 

使用它是如此的简单,包括它,初始化客户端为您的项目,然后执行您的操作:

# 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; 

上的官方客户端库是Cloud Datastore使用最广泛的PHP库,目前仍在使用和运作,它是https://github.com/tomwalder/php-gds

从版本开始3,PHP GDS支持v1 REST API,这意味着您可以在任何计算服务上的App Engine之外使用它。

相关问题