【问题标题】:PHP API for Google Cloud Datastore谷歌云数据存储的 PHP API
【发布时间】:2013-07-03 01:32:21
【问题描述】:

我找不到任何有关 Google 可以数据存储的 PHP API 的文档。我正在尝试将 NoSQL(MongoDB 数据库)网站迁移到 Google App Engine——看来 Cloud Datastore 是目前最好的选择。我能找到的唯一文档是 Node.js、Python 和 Java。

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

【问题讨论】:

标签: php google-app-engine google-cloud-datastore google-cloud-platform


【解决方案1】:

我在这里有一个库:https://github.com/pwhelan/datachore(也可作为 datachore/datachore 从 packagist 获得)。

【讨论】:

    【解决方案2】:

    来自 Google 的 official PHP client library 现在是 GA。

    您可以使用 Composer 安装它:

    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;
    

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

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

    【讨论】:

      猜你喜欢
      • 2014-08-11
      • 1970-01-01
      • 2015-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多