Sample code for 30+ languages & platforms
PHP ActiveX Requires Chilkat v11.6.0+

Azure Table: Get an Entity by Partition and Row Key

See more Azure Table Service Examples

Point lookup with OData apostrophe escaping and percent encoding, including a row key containing an apostrophe, space and plus sign. Validates the returned keys and retains the exact ETag. Entity values stay in memory; they are not logged. Adapt only valid Table keys (at most 1 KiB each; no slash, backslash, #, ?, or control characters).

Targets Azure Storage Table service in the public cloud, not Azure Cosmos DB for Table. Uses Chilkat 11.6.0 or later and an unlocked library. Direct data requests pin x-ms-version 2026-04-06 and OData 3.0. Shared Key examples read private qa_data/azure/storage.json with account and access_key string fields. Authentication examples explain their additional fields. Create private local directories before running; keep credentials, tokens, SAS, entity values, checkpoints and diagnostics outside public content and source control.

HTTPS certificates are verified. Transport completion and HTTP status are checked separately. Writes are not automatically retried after an uncertain outcome. Entity keys, ETags and continuation tokens remain strings. Examples operate on the existing ExampleCustomers table unless noted; review the targets before adapting them. Microsoft Entra ID with suitable Table data roles is preferred where available.

Microsoft reference.

Chilkat PHP ActiveX Downloads

PHP ActiveX
<?php

$success = 0;

//  StringBuilder compares text by value in every generated language.
$textCompare = new COM("Chilkat.StringBuilder");
//  Assumes Chilkat is unlocked. See Global Unlock Sample.
$success = 0;
$config = new COM("Chilkat.JsonObject");
$config->Strict = 1;
$success = $config->LoadFile('qa_data/azure/storage.json');
if ($success != 1) {
    print 'Could not load private Azure configuration.' . "\n";
    exit;
}

$textCompare->Clear();
$textCompare->SetString($config->stringOf('account'));
$sameText1 = $textCompare->ContentsEqual('',1);
if (($config->JsonTypeOf('account') != 1) or ($sameText1 == 1)) {
    print 'Supply the storage account name.' . "\n";
    exit;
}

//  access_key is the base64 account key, not a connection string or SAS.
$textCompare->Clear();
$textCompare->SetString($config->stringOf('access_key'));
$sameText2 = $textCompare->ContentsEqual('',1);
if (($config->JsonTypeOf('access_key') != 1) or ($sameText2 == 1)) {
    print 'Supply the base64 account access key.' . "\n";
    exit;
}

$accountText = new COM("Chilkat.StringBuilder");
$success = $accountText->Append($config->stringOf('account'));
if ($success != 1) {
    print 'Could not prepare the request.' . "\n";
    exit;
}

if (($accountText->Length < 3) or ($accountText->Length > 24)) {
    print 'Storage account names need 3-24 lowercase letters or digits.' . "\n";
    exit;
}

$allowedAccountChars = new COM("Chilkat.StringBuilder");
$success = $allowedAccountChars->Append('abcdefghijklmnopqrstuvwxyz0123456789');
if ($success != 1) {
    print 'Could not prepare the request.' . "\n";
    exit;
}

$charIndex = 0;
while (($charIndex < $accountText->Length)) {
    if ($allowedAccountChars->Contains($accountText->getRange($charIndex,1,0),1) != 1) {
        print 'Storage account names need lowercase letters or digits.' . "\n";
        exit;
    }

    $charIndex = $charIndex + 1;
}

$endpoint = new COM("Chilkat.StringBuilder");
$success = $endpoint->Append($config->stringOf('account'));
if ($success != 1) {
    print 'Could not prepare the request.' . "\n";
    exit;
}

$success = $endpoint->Append('.table.core.windows.net');
if ($success != 1) {
    print 'Could not prepare the request.' . "\n";
    exit;
}

//  Table names contain only letters and digits and are case-insensitive.
//  Entity PartitionKey and RowKey values are case-sensitive.
$resourcePath = '/ExampleCustomers()';
$rest = new COM("Chilkat.Rest");
$rest->ConnectTimeoutMs = 20000;
$rest->IdleTimeoutMs = 60000;
$azAuth = new COM("Chilkat.AuthAzureStorage");
$azAuth->Account = $config->stringOf('account');
$azAuth->AccessKey = $config->stringOf('access_key');
$azAuth->Service = 'Table';
$azAuth->Scheme = 'SharedKey';
$azAuth->XMsVersion = '2026-04-06';
$success = $rest->SetAuthAzureStorage($azAuth);
if ($success != 1) {
    print 'Could not configure Shared Key signing.' . "\n";
    exit;
}

$connection = new COM("Chilkat.Socket");
$connection->RequireSslCertVerify = 1;
$connection->MaxReadIdleMs = 60000;
$connection->MaxSendIdleMs = 60000;
$success = $connection->Connect($endpoint->getAsString(),443,1,20000);
if ($success != 1) {
    print 'TLS connection failed; inspect diagnostics privately.' . "\n";
    exit;
}

//  Do not replay a write automatically after losing its response.
$success = $rest->UseConnection($connection,0);
if ($success != 1) {
    print 'Could not prepare the request.' . "\n";
    exit;
}

$result = new COM("Chilkat.JsonObject");
$result->Strict = 1;
$success = $rest->AddHeader('DataServiceVersion','3.0;NetFx');
if ($success != 1) {
    print 'Could not prepare the request.' . "\n";
    exit;
}

$success = $rest->AddHeader('MaxDataServiceVersion','3.0;NetFx');
if ($success != 1) {
    print 'Could not prepare the request.' . "\n";
    exit;
}

$success = $rest->AddHeader('Content-Type','application/json');
if ($success != 1) {
    print 'Could not prepare the request.' . "\n";
    exit;
}

$success = $rest->AddHeader('Accept','application/json;odata=minimalmetadata');
if ($success != 1) {
    print 'Could not prepare the request.' . "\n";
    exit;
}

$partitionKey = 'customers-west';
$rowKey = 'O'Brien + 01';
$encodedPk = new COM("Chilkat.StringBuilder");
$success = $encodedPk->Append($partitionKey);
if ($success != 1) {
    print 'Could not prepare the request.' . "\n";
    exit;
}

$escapedencodedPk = $encodedPk->Replace(''','''');
$success = $encodedPk->Encode('url_rfc3986','utf-8');
if ($success != 1) {
    print 'Could not prepare the request.' . "\n";
    exit;
}

$encodedRk = new COM("Chilkat.StringBuilder");
$success = $encodedRk->Append($rowKey);
if ($success != 1) {
    print 'Could not prepare the request.' . "\n";
    exit;
}

$escapedencodedRk = $encodedRk->Replace(''','''');
$success = $encodedRk->Encode('url_rfc3986','utf-8');
if ($success != 1) {
    print 'Could not prepare the request.' . "\n";
    exit;
}

//  Escape apostrophes for OData first, then percent-encode each key once.
$entityPath = new COM("Chilkat.StringBuilder");
$success = $entityPath->Append('/ExampleCustomers(PartitionKey='');
if ($success != 1) {
    print 'Could not prepare the request.' . "\n";
    exit;
}

$success = $entityPath->Append($encodedPk->getAsString());
if ($success != 1) {
    print 'Could not prepare the request.' . "\n";
    exit;
}

$success = $entityPath->Append('',RowKey='');
if ($success != 1) {
    print 'Could not prepare the request.' . "\n";
    exit;
}

$success = $entityPath->Append($encodedRk->getAsString());
if ($success != 1) {
    print 'Could not prepare the request.' . "\n";
    exit;
}

$success = $entityPath->Append('')');
if ($success != 1) {
    print 'Could not prepare the request.' . "\n";
    exit;
}

$resourcePath = $entityPath->getAsString();
$responseText = $rest->fullRequestNoBody('GET',$resourcePath);
if ($rest->LastMethodSuccess != 1) {
    print 'Request did not complete; inspect the target before retrying a write.' . "\n";
    exit;
}

if ($rest->ResponseStatusCode != 200) {
    print 'HTTP status: ' . $rest->ResponseStatusCode . "\n";
    print 'Request ID: ' . $rest->responseHdrByName('x-ms-request-id') . "\n";
    //  404 is missing, 409 is conflict, and 412 is a stale ETag: none are success.
    //  Keep response bodies private. Reconcile uncertain writes before retrying.
    exit;
}

$success = $result->Load($responseText);
if ($success != 1) {
    print 'Expected well-formed JSON.' . "\n";
    exit;
}

$textCompare->Clear();
$textCompare->SetString($result->stringOf('PartitionKey'));
$sameText3 = $textCompare->ContentsEqual('',1);
if (($result->JsonTypeOf('PartitionKey') != 1) or ($sameText3 == 1)) {
    print 'Missing string PartitionKey.' . "\n";
    exit;
}

$textCompare->Clear();
$textCompare->SetString($result->stringOf('RowKey'));
$sameText4 = $textCompare->ContentsEqual('',1);
if (($result->JsonTypeOf('RowKey') != 1) or ($sameText4 == 1)) {
    print 'Missing string RowKey.' . "\n";
    exit;
}

$textCompare->Clear();
$textCompare->SetString($result->stringOf('PartitionKey'));
$sameText5 = $textCompare->ContentsEqual($partitionKey,1);
$textCompare->Clear();
$textCompare->SetString($result->stringOf('RowKey'));
$sameText6 = $textCompare->ContentsEqual($rowKey,1);
if (($sameText5 != 1) or ($sameText6 != 1)) {
    print 'Returned entity keys do not match.' . "\n";
    exit;
}

$entityEtag = $rest->responseHdrByName('ETag');
$textCompare->Clear();
$textCompare->SetString($entityEtag);
$sameText7 = $textCompare->ContentsEqual('',1);
$textCompare->Clear();
$textCompare->SetString($entityEtag);
$sameText8 = $textCompare->ContentsEqual('*',1);
if (($sameText7 == 1) or ($sameText8 == 1)) {
    print 'Missing exact entity ETag.' . "\n";
    exit;
}

print 'Entity retrieved; payload remains in result.' . "\n";
print 'ETag: ' . $entityEtag . "\n";

?>