如何在azure表中检索超过1000行php

时间:2016-08-08 13:07:52

标签: php azure

我试图在php中从azure获得超过1000行。 首先,我无法使用过滤器类。需要添加哪个命名空间才能使用过滤器类 之后while循环是gng无限循环 任何帮助

$ tableRestProxy = ServicesBuilder :: getInstance() - > createTableService($ this-> connectionString);     $ filter =“(PartitionKey eq'$ id')”;

$options = new QueryEntitiesOptions();
$options->setFilter(Filter::applyQueryString($filter));

$result = $tableRestProxy->queryEntities('test', $options);
$entities = $result->getEntities();

$nextPartitionKey = $result->getNextPartitionKey();
$nextRowKey = $result->getNextRowKey();

while (!is_null($nextRowKey) && !is_null($nextPartitionKey) ) {

    $options = new QueryEntitiesOptions();
    $options->setNextPartitionKey($nextPartitionKey);
    $options->setNextRowKey($nextRowKey);
    $options->setFilter(Filter::applyQueryString($filter));

    $result2 = $tableRestProxy->queryEntities("test", $options);
    $newentities = $result2->getEntities();
    $entities=array_merge($newentities, $entities);    

}

使用链接m PHP - Azure Table Storage in with more than 1000 entities

1 个答案:

答案 0 :(得分:0)

您可以利用MicrosoftAzure\Storage\Table\Models\QueryEntitiesOptions类的setTop()函数来选择表格的前X(数字)实体。

根据https://github.com/Azure/azure-storage-php/blob/master/src/Table/Models/QueryEntitiesOptions.php#L148的说明,我们可以发现过滤器类已进入namespace MicrosoftAzure\Storage\Table\Models\Filters

如果要在新的Azure Storage SDK for PHP中使用过滤器类,可以尝试将该包包含为:

use MicrosoftAzure\Storage\Table\Models\Filters\QueryStringFilter;

请考虑以下代码段:

use MicrosoftAzure\Storage\Table\Models\QueryEntitiesOptions;
use MicrosoftAzure\Storage\Table\Models\Filters\QueryStringFilter;
$options = new QueryEntitiesOptions();
$filter = new QueryStringFilter("(RowKey eq '".$id."')");
$options->setFilter($filter);
$options->setTop(1000);