1

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 :)

scottstots
  • 155
  • 2
  • 17

1 Answers1

0

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 />";
}
Tom Sun - MSFT
  • 24,161
  • 3
  • 30
  • 47
  • I tried using the above method, but I get an error saying: `Error creating resource: [message] fopen(https://eyesav.table.core.windows.net/Tables): failed to open stream: Unable to find the socket transport "http" - did you forget to enable it when you configured PHP?` – scottstots Sep 03 '18 at 12:28
  • It means that you need enable https . You could test with connection string DefaultEndpointsProtocol=http. to intsead of https. – Tom Sun - MSFT Sep 03 '18 at 12:40
  • I tried the connection string with http:// but it gives the same error. How do I enable http? – scottstots Sep 03 '18 at 17:01
  • Please try to connection string `$connectionString = 'DefaultEndpointsProtocol=http;AccountName=xxxx;AccountKey=xxxxxxx;';` – Tom Sun - MSFT Sep 04 '18 at 02:16
  • About how to enable https please refer to this [SO thread](https://stackoverflow.com/questions/2305954/how-to-enable-https-stream-wrappers) – Tom Sun - MSFT Sep 04 '18 at 02:20
  • This might work for Windows but not Ubuntu, while I am working on Ubuntu. – scottstots Sep 04 '18 at 12:50