drwjv28028 2018-09-01 07:21
浏览 112
已采纳

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

I have created the composer.json file in my root folder where my index.php file is presents, with the following code in it:

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

and on downloading composer.phar, I have installed it using:

php composer.phar install

I'm trying to create a table and add entities to it in php. I use the command

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 />";
}

When I run this on local host on my Ubuntu, I get an error saying-

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

If I add

require_once 'vendor/autoload.php';

before defining my $connectionString, then my error changes to:

/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?

Can someone help me figure out this issue, if it is with the installation of my composer, or my connectionString, or something else?

Thanks in advance :)

  • 写回答

1条回答 默认 最新

  • doskmc7870 2018-09-03 07:05
    关注

    Can someone help me figure out this issue, if it is with the installation of my composer, or my connectionString, or something else?

    If I use the code you mentioned, I also could reproduce the issue you mentioned.

    Please have a try to use following code to create the table client. It works for me.

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

    The following is the demo code from 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 />";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog