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

报告相同问题?

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装