Uncaught Error: Class 'WindowsAzure\Common\ServicesBuilder' not found- MS Azure | PHP - 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 "http" - 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 :)

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

Related

ΜongoDB PHP, Error: Call to undefined method MongoDB\Driver\Manager::getEncryptedFieldsMap()

I am trying to create a collection on my MongoDB database using PHP but I am getting the following error
*Uncaught Error: Call to undefined method MongoDB\Driver\Manager::getEncryptedFieldsMap() *
I have downloaded and added the MongoDB PHP Driver, via the php_mongodb.ddl file (have made sure to download the correct driver version for my php version), and have added the MongoDB PHP Library via Composer using the composer require jenssegers/mongodb --ignore-platform-reqs, all with no errors.
My code is the following:
<?php
require 'vendor/autoload.php';
$client = new MongoDB\Client("mongodb://127.0.0.1/");
echo "connected succ <br><br>";
$db = $client->webVacSer;
echo "db sellected successfully <br><br>";
$collection = $db->createCollection("customers");
echo "collection created successfully <br><br>";
?>
What is wrong?

Composer not generating autoload files package made by me

I hate to add more to the noise of "autoload isn't working!!!!!", but I can't seem to get this problem figured out, and I figured getting some fresh eyes on it would get the problem in a lot less time. Here is my index.php file:
<?php
declare(strict_types=1);
require_once 'vendor/autoload.php';
require_once 'model/PageNav.php';
use ShinePHP\{Crud, CrudException, EasyHttp, EasyHttpException, HandleData, HandleDataException};
// ALWAYS serve over encrypted channels
try {
EasyHttp::checkHttps();
} catch (EasyHttpException $ex) {
echo $ex;
}
try {
// check if it's a GET request, if it is, serve page, if not, do nothing
if (EasyHttp::isRequestMethod('GET')) {
$Page = new PageNav('Home', 'view/home.php');
$Page->buildPage();
exit;
}
}
catch (EasyHttpException $ex) {
echo $ex;
}
So obviously I am using a package from composer called ShinePHP (it's one I've made, and I'm still working on the documentation, so I'm just using it for my own projects at the moment, composer just makes package management so easy!)
ANYWAYS...because I'm writing this question, I'm obviously getting the following error:
Fatal error: Uncaught Error: Class 'ShinePHP\EasyHttp' not found in /Applications/XAMPP/xamppfiles/htdocs/KRTY/src/index.php:11 Stack trace: #0 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/KRTY/src/index.php on line 11
Now, I haven't manually touched the composer.json file, so here it is:
{
"require": {
"adammcgurk/shine-php": "~0.0.1"
},
"autoload": {
"psr-4": {
"ShinePHP\\": "src/"
}
}
}
I'm not getting any errors on requiring the vendor/autoload.php file (and I've tried changing the path to something that doesn't exist like vendor/alkdjfladksf/autoload.php and it throws an error how it should), I'm running PHP version 7.2.7 on XAMPP on Mac OS Mojave. Here is the directory structure, the highlighted index.php file is the one with the code above:
And here is the output of composer dump-autoload -o:
Generating optimized autoload files
And so...to add more to the fire of this question on Stack...How can I get composer to autoload my ShinePHP namespace with the classes as shown in the code?
This dependency does not have any autoloading rules, so Composer does not know where to find ShinePHP\EasyHttp class. You need to add autoloading configuration in composer.json of shine-php package:
"autoload": {
"psr-4": {
"ShinePHP\\": "src/"
}
},

SSH in xampp install php

I need to use a connection SSH and PHP, I have version PHP 5.6.8 ,
intall OpenSSL-Win32;
In php.ini :
extension=libssh2.dll ;librerias ssl2
extension=php_ssh2.dll
The libraries are in the folder php---->ext.
With the next program my result is:
Fatal error: Call to undefined function ssh2_connect() in
C:\xampp\htdocs\conexion\conexion_ssh.php on line 2
<?php
$connection = ssh2_connect('X.X.X.X', XX);
if (ssh2_auth_password($connection, 'root', 'XXXXXXXX')) {
echo "Authentication Successful!\n";
} else {
die('Authentication Failed...');
}
?>
Do you know the problem? I think is the configuration the system variable PATH but I don't Know the process.
Thanks for you help me!

Elastic search configuration issue with client call php

I am using elasticsearch API php to build search results. I have configured everything in my xampp server. All the libraries downloaded from composer.json. In my composer.json file contains below code
{
"require": {
"elasticsearch/elasticsearch": "~2.0"
}
}
Libraries are successfully downloaded. After that i initialize the elastic search with below code
<?php
require 'vendor/autoload.php';
$client = ClientBuilder::create()->build();
It shows fatal error like as follows
Fatal error: Class 'ClientBuilder' not found in E:\Xampp\htdocs\codeporn\elasticsearch\app\init.php on line 4
So i change the config code as,
require_once 'vendor/autoload.php';
$es = new Elasticsearch\Client([
'hosts' => ['127.0.0.1:9200']]
]);
This also shows error like
Parse error: syntax error, unexpected ']' in E:\Xampp\htdocs\codeporn\elasticsearch\app\init.php on line 10
I am following the below youtube tutorial to build the search
https://www.youtube.com/watch?v=3xb1dHLg-Lk
Please suggest what i went wrong in Elasticsearch - PHP.
My PHP Version is 5.5.9
i have initialize the clientbuilder class, now it works fine
require 'vendor/autoload.php';
use Elasticsearch\ClientBuilder;
$client = ClientBuilder::create()->build();
you need install it with composer
composer require elasticsearch/elasticsearch

Start Solarium Client

I have problem with start Solarium Client, I downloaded it by Composer and GitHub according the wiki tutorial, it's ok, but I don't know what I must do now.
When I tried this example code:
<?php
require(__DIR__.'/init.php');
htmlHeader();
// check solarium version available
echo 'Solarium library version: ' . Solarium\Client::VERSION . ' - ';
// create a client instance
$client = new Solarium\Client($config);
// create a ping query
$ping = $client->createPing();
// execute the ping query
try {
$result = $client->ping($ping);
echo 'Ping query successful';
echo '<br/><pre>';
var_dump($result->getData());
echo '</pre>';
} catch (Solarium\Exception $e) {
echo 'Ping query failed';
}
htmlFooter();
I have the following error:
Warning: require(C:\xampp\htdocs\solarium/init.php): failed to open stream: No such file or directory in C:\xampp\htdocs\solarium\test.php on line 3
Fatal error: require(): Failed opening required 'C:\xampp\htdocs\solarium/init.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\solarium\test.php on line 3
I use Xampp server.
Must I set some Path, where appropriate, how and where? File init.php is in folder: C:\xampp\htdocs\solarium\vendor\solarium\solarium\examples\ and i start the demo file in folder: C:\xampp\htdocs\solarium\
Sorry for my English. Thank you for help.
You have to run solarium examples, and examples derived form them like your test.php file, from the /examples directory in the solarium directory tree.
In this directory there is init.php file which is setting up 'display_errors' init variable, loading composer created autoload.php, loading the config.php and defining htmlHeader() and htmlFooter() functions.

Categories