Google刚刚宣布支持App Engine的PHP运行时。我有一个使用Java运行时开发的应用程序,它利用了原生app Engine数据存储。它目前的功能是作为移动客户端的后端。我们正在研究开发一个单独的web前端,它需要连接这个数据存储。从事这项工作的开发人员更喜欢用PHP进行开发,所以发布这个消息的时机很有趣。
然而,浏览文档时,我只在“存储数据”下看到对Google Cloud SQL和Google Cloud Storage的引用。是否可以使用PHP运行时连接原生App Engine数据存储?
发布于 2013-05-17 12:00:47
在I/O上,我们还宣布了Cloud Datastore,这是目前您应该如何考虑从PHP应用程序访问数据存储的方式。
发布于 2013-08-26 15:11:28
注意:您不需要启用计算引擎
确保在管理控制台上的应用程序设置云集成部分显示‘项目已成功创建。有关如何在AppEngine https://gaeforphp-blog.appspot.com/2013/08/06/using-the-google-apis-client-library-for-php-with-app-engine/
<?php
const SERVICE_ACCOUNT_NAME = 'your-service-account-id@developer.gserviceaccount.com';
require_once 'libraries/google-api-php-client/src/Google_Client.php';
require_once 'libraries/google-api-php-client/src/contrib/Google_DatastoreService.php';
$client = new Google_Client();
$client->setApplicationName("your_app_id");
$key = file_get_contents('storage/your-hashed-keyid-privatekey.p12');
$client->setAssertionCredentials(
new Google_AssertionCredentials(
SERVICE_ACCOUNT_NAME,
array('https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/datastore'),
$key)
);
$datastore = new Google_DatastoreService($client);
$lookup = new Google_LookupRequest();
$path1 = new Google_KeyPathElement();
$path1->setKind('Guestbook');
$path1->setName('default_guestbook');
$path2 = new Google_KeyPathElement();
$path2->setKind('Greeting');
# this is just an example check a real entity id in your datastore
# if you do not have ancestor entity you only need one (path1) element
$path2->setId('5733953138851840');
$key = new Google_Key();
$key->setPath([$path1,$path2]);
$keyArray = array();
$keyArray[] = $key;
$lookup->setKeys($keyArray);
if(array_key_exists('catchError', $_GET)){
try{
$result = $datastore->datasets->lookup('your_project_name', $lookup);
var_dump($result);
}
catch(Google_ServiceException $e){
echo "<pre>";
var_dump($e);
echo "</pre>";
}
}
else{
$result = $datastore->datasets->lookup('your_project_name', $lookup);
var_dump($result);
}
发布于 2015-02-18 08:03:28
这个库是最近(由我)发布的-我希望它能帮助人们找到这个帖子。
它使得从PHP (在App Engine上或不在App Engine上)使用数据存储变得更加容易。
https://github.com/tomwalder/php-gds
享受吧!
https://stackoverflow.com/questions/16601074
复制相似问题