How to use Azure documentdb with php

Does anyone know how to work with azure db document using php.

I want to create a collection, add data to db document using php.

please post a sample code for it.

http://azure.microsoft.com/en-in/services/documentdb/

thank

Thanigaivelan

+3


source to share


2 answers


Currently DocumentDB does not have an official PHP SDK client.

You can interact with DocumentDB using the REST API .



Alternatively, you can search for unofficial third party SDKs like this one (I'm not sure how well supported this project is - but the source code looks like a good reference for interacting with the REST API).

+3


source


Documentdb offers a REST API, so you need a REST API client. You can write one as you like, or use one of the 3 available on github (search php documentdb)

Basically you need to request the resource you want via POST and add the required headers using CURL. The only tricky part is the authorization token, which needs to be generated based on various information. Here is the code snippet for the token:

function gettoken($master_key,$vrb,$rtype,$rid,$da_date) {
$key = base64_decode($master_key);
$st_to_sign = $vrb . "\n" .
$rtype . "\n" .
$rid . "\n" .
$da_date . "\n" .
"\n";
$sig = base64_encode(hash_hmac('sha256', strtolower($st_to_sign), $key, true));
return $sig;
}

      



My repo on github is a nice, easy way to get started, but not oop. ( https://github.com/upggr/documentdb-for-php )

There are currently 2 more repo's that provide a full API via a class: One from cocteau666 mentioned in a previous comment and one from crassaert ( https://github.com/crassaert/php-azure-documentdb )

For some reason, there is no user interest in PHP yet, I hope that will change soon.

+1


source







All Articles