我有一个azure表存储,其中有一些实体。建立新的实体不成问题。更新现有的实体也没有问题,这一切都很好。
$result = $tableClient->retrieveEntities('users',"Name eq 'John Doe'",'partition1');
(在底部某处)给出http 500错误。
require_once("Microsoft/WindowsAzure/Storage/Table.php");
require_once("Microsoft/WindowsAzure/Storage/DynamicTableEntity.php");
$accountName = '***';
$accountKey = '*****';
$tableClient = new Microsoft_WindowsAzure_Storage_Table('table.core.windows.net',$accountName,$accountKey);
$tableClient->createTableIfNotExists('users');
$result = $tableClient->listTables();
foreach ($result as $table){
echo 'Table name is: ' . $table->Name . "rn<br />";
}
function setUser($accountName,$accountKey,$partitionName,$data) {
$tableClient = new Microsoft_WindowsAzure_Storage_Table('table.core.windows.net',$accountName,$accountKey);
$update = false;
if(isset($data['ID']) && $entity = $tableClient->retrieveEntityById('users',$partitionName,$data['ID'])){
$update = true;
unset($data['ID']);
} else {
$guid = substr(com_create_guid(),1,32);
$entity = new Microsoft_WindowsAzure_Storage_DynamicTableEntity($partitionName, $guid);
$entity->ID = $guid;
}
$keys = array_keys($data);
foreach($keys as $key){
$entity->$key = $data[$key];
}
if($update){
$tableClient->updateEntity('users',$entity,true);
} else {
$tableClient->insertEntity('users',$entity);
}
}
setUser($accountName,$accountKey,'partition1',array(Name => 'John Doe',Email => 'johndoe@gmail.com',Time => time()));
$result = $tableClient->retrieveEntities('users',"Name eq 'John Doe'",'partition1');
//$result = $tableClient->retrieveEntities('users');
foreach($result as $data) {
echo $data->ID;
echo ' - ';
echo $data->Name;
echo ' - ';
echo $data->Email;
echo ' - ';
echo $data->Time;
echo '<br />';
}
我想知道的是;
我对过滤器参数做错了什么?(当我用过滤器注释掉一行并取消注释下面一行时,它工作得很好)。
我如何捕获此错误(和其他类似的错误),我尝试了try {} catch{},但这不起作用。
try-catch - code:
try {
$result = $tableClient->retrieveEntities('users',"Name eq 'John Doe'",'partition1');
} catch (Microsoft_WindowsAzure_Exception $e) {
echo 'Caught exception: '.$e->getMessage();
}
只是胡乱猜测(所以我可能是错的)-我在这里查看了检索实体的代码:https://github.com/Daniel15/AjaXplorer-Azure/blob/master/azuresdk/Microsoft/WindowsAzure/Storage/Table.php(希望我看对了地方),并注意到您正在传递partition1
作为方法的参数之一。
这会导致问题吗?试试这样写:
$tableClient->retrieveEntities('users',"PartitionKey eq 'partition1' and Name eq 'John Doe'")
我还查看了CodePlex上的项目页面(http://phpazure.codeplex.com/),上面提到这个项目已经被弃用,转而支持Github上的Azure SDK (https://github.com/Azure/azure-sdk-for-php)。恕我直言,投入一些时间来移植应用程序以使用新的SDK可能是值得的。只是一个想法。