php - 未捕获的错误:找不到类 'WindowsAzure\Common\ServicesBuilder' - MS Azure | PHP
问题描述
我在我的 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 "http" - did you forget to enable it when you configured PHP?
有人可以帮我解决这个问题,如果它与我的作曲家、我的连接字符串或其他东西的安装有关吗?
提前致谢 :)
解决方案
有人可以帮我解决这个问题,如果它与我的作曲家、我的连接字符串或其他东西的安装有关吗?
如果我使用你提到的代码,我也可以重现你提到的问题。
请尝试使用以下代码创建表客户端。这个对我有用。
use MicrosoftAzure\Storage\Table\TableRestProxy;
use MicrosoftAzure\Storage\Common\ServiceException;
$tableClient = TableRestProxy::createTableService($connectionString);
以下是 azure官方文档中的演示代码。
<?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 />";
}