My puppyのブログ

学んだ事や作っているプログラムなどについて書いています。

DocumentDBをPHPから動かす方法。

まずはMicrosoft AzureのDocumentDBの公式サイトです。

azure.microsoft.com

このDocumentDBをPHPで動かす時に、下の「documentdb-for-php」で試したらうまく動きましたのでメモっておきますね。

github.com

下記のコードは上のリンク先のサンプルからの引用です。

include 'documentdb-for-php.php';
$host = 'https://yourdocumentdbaccount.documents.azure.com'; // see (1) in the screenshots bellow
$master_key = 'yourmasterkey=='; // see (2) in the screenshots bellow
$db = 'yourdbname'; // see (3) in the screenshots bellow (optional)
$db_rid = 'thedbresourceid=='; // see (4) in the screenshots bellow
$coll = 'yourcollectionname'; // see (5) in the screenshots bellow (optional)
$coll_rid = 'yourcollectionresourceid='; // see (6) in the screenshots bellow
$query = "Select * from ..."; // This is your SQL or LINQ code
querycoll($host, $db_rid, $coll_rid,$query,$apptype,$useragent,$cachecontrol,$da_date,$api_version,$master,$token,$master_key,$da_date); //The function that does the magic. All variables are defined above and in the functions file

リンク先のサンプルの通りに上記の$hostや$master_key、$db、$db_ridなどを一通り設定すればすぐに動きました。

ちなみに以下の2つも試してみたのですが、エラーが出てうまく動きませんでした。

github.com

github.com