未捕获的错误:未找到类'WindowsAzure \ Common \ ServicesBuilder' - MS Azure | PHP

问题描述 投票:1回答:1

我在我的index.php文件所在的根文件夹中创建了composer.json文件,其中包含以下代码:

{
 "require": {
    "microsoft/windowsazure": "^0.5"
 }
}

并在下载composer.phar时,我使用以下方法安装它:

php composer.phar install

我正在尝试创建一个表并在php中添加实体。我用这个命令

use WindowsAzure\Common\ServicesBuilder;
$connectionString = 'DefaultEndpointsProtocol=https;AccountName=******;AccountKey=***/***************************/******************/**********************************==';
$tableRestProxy = ServicesBuilder::getInstance()->createTableService($connectionString);
try {
  // Create table.
  $tableRestProxy->createTable("mytable");
}
catch(ServiceException $e){
  $code = $e->getCode();
  $error_message = $e->getMessage();
  echo $code.": ".$error_message."<br />";
}

当我在我的Ubuntu上的本地主机上运行它时,我得到一个错误 -

Uncaught Error: Class 'WindowsAzure\Common\ServicesBuilder' not found in /home/my_folder/php-docs-hello-world-master/index.php:30

如果我加

require_once 'vendor/autoload.php';

在定义我的$ connectionString之前,我的错误更改为:

/index.php - Uncaught RuntimeException: Error creating resource: [message] fopen(https://eyesav.table.core.windows.net/Tables): failed to open stream: Unable to find the socket transport &quot;http&quot; - did you forget to enable it when you configured PHP?

有人可以帮我弄清楚这个问题,如果是安装了我的作曲家,还是我的connectionString,还是别的什么?

提前致谢 :)

php azure connection-string azure-table-storage
1个回答
0
投票

有人可以帮我弄清楚这个问题,如果是安装了我的作曲家,还是我的connectionString,还是别的什么?

如果我使用您提到的代码,我也可以重现您提到的问题。

请尝试使用以下代码来创建表客户端。这个对我有用。

 use MicrosoftAzure\Storage\Table\TableRestProxy;
 use MicrosoftAzure\Storage\Common\ServiceException;
 $tableClient = TableRestProxy::createTableService($connectionString);

以下是azure official document的演示代码。

<?php 
require_once "vendor/autoload.php";
use MicrosoftAzure\Storage\Table\TableRestProxy;
use MicrosoftAzure\Storage\Common\ServiceException;
$connectionString = 'DefaultEndpointsProtocol=https;AccountName=xxxx;AccountKey=xxxxxxx;';
$tableClient = TableRestProxy::createTableService($connectionString);
try {
    $tableClient->createTable("mytable");
}
catch(ServiceException $e){
  $code = $e->getCode();
  $error_message = $e->getMessage();
  echo $code.": ".$error_message."<br />";
}
© www.soinside.com 2019 - 2024. All rights reserved.