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

报告相同问题?