I installed Foolz SphinxQL Query Builder for PHP with composer using the following json file:
{
"require": {
"foolz/sphinxql-query-builder": "^2.0"
}
}
My php is as follows:
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Foolz\SphinxQL\SphinxQL;
use Foolz\SphinxQL\Connection;
error_reporting(E_ALL);
ini_set('display_errors', 1);
// create a SphinxQL Connection object to use with SphinxQL
$conn = new Connection();
$conn->setConnectionParams('127.0.0.1', 9306);
$query = SphinxQL::create($conn)->select('*')
->from('test1')
->match('#test document');
# ->where('banned', '=', 1);
$result = $query->execute();
var_dump($result);
?>
Using my debugger I see the autoloader (function findFileWithExtension) is trying to find the file at /mnt/i/var/www/vhosts/my.play.net/sphinx/vendor/composer/../foolz/sphinxql-query-builder/Connection.php when it should presumably be looking in /mnt/i/var/www/vhosts/my.play.net/sphinx/vendor/composer/../foolz/sphinxql-query-builder/Drivers/Mysqli/Connection.php where it is actually located.
Can anyone advise why I might be seeing this and how I fix it?
You're using incorrect namespace. To get vendor/foolz/sphinxql-query-builder/src/Drivers/Mysqli/Connection.php you need to use Foolz\SphinxQL\Drivers\Mysqli\Connection as FQN:
use Foolz\SphinxQL\SphinxQL;
use Foolz\SphinxQL\Drivers\Mysqli\Connection;
Related
I need to access a file on SharePoint and I have installed phpSPO via Composer.
I use this code:
require_once('/vendor/autoload.php');
$username = 'myUsername';
$password = 'myPassword';
$fileUrl = "file-url";
$fileUrl = end(explode("https://xxxxxxxx.sharepoint.com", $fileUrl));
use Office365\PHP\Client\Runtime\Auth\AuthenticationContext;
use Office365\PHP\Client\SharePoint\ClientContext;
use Office365\PHP\Client\SharePoint\ListCreationInformation;
use Office365\PHP\Client\SharePoint\SPList;
$authCtx = new AuthenticationContext('https://xxxxxxxx.sharepoint.com');
But I get this error: Fatal error: Uncaught Error: Class "Office365\PHP\Client\Runtime\Auth\AuthenticationContext" not found ...
From composer.json:
{
"require": {
"vgrem/php-spo": "^2.5"
}
}
Any ideas?
Solution:
use Office365\Runtime\Auth\AuthenticationContext;
use Office365\SharePoint\ClientContext;
use Office365\SharePoint\ListCreationInformation;
use Office365\SharePoint\SPList;
Im using this library https://serp-spider.github.io/documentation/search-engine/google/
When I follow their example I got this.
Fatal error: Uncaught Error: Class "Serps\SearchEngine\Google\GoogleClient" not found in /var/www/html/index.php:19 Stack trace: #0 {main} thrown in /var/www/html/index.php on line 19
This is my index.php
<?php
use Serps\SearchEngine\Google\GoogleClient;
use Serps\SearchEngine\Google\GoogleUrl;
$googleClient = new Serps\SearchEngine\Google\GoogleClient($httpClient);
$googleUrl = new GoogleUrl();
$google->setSearchTerm('simpsons');
$response = $googleClient->query($googleUrl);
$results = $response->getNaturalResults();
foreach($results as $result){
// Here we iterate over the result list
// Each result will have different data based on its type
}
?>
I've been thinking about what it could be for a while but I can't
I was missing the autoload, I added this line and works.
require 'vendor/autoload.php';
I changed the namespace and forgot to update it in composer.json
"autoload": {
"psr-4": {
"MyNamespace\\": "src"
}
},
Then run composer dump-autoload
I am using a third party class that works well as long as I use it in the main body of my PHP script. If I try to use it in a function that is called from main, it gets a "PHP Fatal error: Class 'RouterOS\Util' not found error". What do I need to do in the function so it can use the class?
<?php
require_once '/usr/local/sbrc/MTAPI/vendor/autoload.php';
...
GetNextRouter($loginData[0]['User'], $loginData[0]['Password'], $firstAddress[0]['IPAddress']);
...
}
function GetNextRouter($UserID, $Pass, $Address) {
$util = new RouterOS\Util($client = new RouterOS\Client($Address, $UserID, $Pass));
...
}
The error occurs on the $util = new RouterOS\Util line.
Adding
use PEAR2\Net\RouterOS;
solved my issue
So my basic slim app goes along these lines:
<?php
session_start();
if (!file_exists( __DIR__ . '/settings.php')) { die("Error 500: application configuration problem."); }
require __DIR__ . '/../vendor/autoload.php';
$config = require __DIR__ . '/settings.php';
$app = new \Slim\App($config);
$container = $app->getContainer();
$container['s4s'] = function ($container) {
$db = $container['settings']['s4s'];
return new PDO('sqlsrv:Server='.$db['host'].';Database='.$db['database'], $db['username'], $db['password']);
};
$app->get('/ff', function ($request, $response) {
$sql = 'SELECT "dbo"."ZAKAZKA"."ZAKAZKA ID" FROM "dbo"."ZAKAZKA" WHERE ("ZAKAZKA ID" LIKE \'1216%\' ) ORDER BY "dbo"."ZAKAZKA"."ZAKAZKA ID" DESC';
$stmt = $this->s4s->prepare($sql);
if($stmt->execute()){
echo $stmt->debugDumpParams();
$results=$stmt->fetchAll();
}
});
this works fine and dandy. If I move the query code to a controller
<?php
namespace Glued\Playground;
use \PDO;
use Glued\Controllers\Controller;
class pdo_test extends Controller
{
public function test($request, $response)
{
$sql = 'SELECT "dbo"."ZAKAZKA"."ZAKAZKA ID" FROM "dbo"."ZAKAZKA" WHERE ("ZAKAZKA ID" LIKE \'1216%\' ) ORDER BY "dbo"."ZAKAZKA"."ZAKAZKA ID" DESC';
echo $sql;
$stmt = $this->container->s4s->prepare($sql); // this line breaks things
if($stmt->execute()){
echo $stmt->debugDumpParams();
$results=$stmt->fetchAll();
}
}
}
and add to the main code
$app->get('/playground/fff', '\Glued\Playground\Pdo_test::mytest');
it starts to break at the $stmt assignment with the error
PHP Fatal error: Uncaught RuntimeException: Unexpected data in output buffer. Maybe you have characters before an opening finalize(Object(Slim\Http\Response))\n#1 /opt/Web/html/glued/vendor/slim/slim/Slim/App.php(298): Slim\App->process(Object(Slim\Http\Request), Object(Slim\Http\Response))\n#2 /opt/Web/html/glued/public/index.php(4): Slim\App->run()\n#3 {main}\n thrown in /opt/Web/html/glued/vendor/slim/slim/Slim/App.php on line 552
since this doesnt apply to other controllers I wrote sofar, I'm either overlooking something obvious or PDO (which I dont usually use) causes the premature output. Not sure how to debug this as well.
Hints and solutions very welcome, thanks in advance!
note: I usually dont work with mssql as well, but I got the same problem against a mysql db.
This is my PHP code
<?php
// Load Azure Drivers
require_once '../vendor/autoload.php';
use WindowsAzure\Common\ServicesBuilder;
use MicrosoftAzure\Storage\Common\ServiceException;
use MicrosoftAzure\Storage\Table\Models\QueryEntitiesOptions;
// Connection String
$connectionString = 'DefaultEndpointsProtocol=https;AccountName=<account_name>;AccountKey=<account_key>==';
// Create table REST proxy.
$tableRestProxy = ServicesBuilder::getInstance()->createTableService($connectionString);
$user_input = "Username eq '<user>'";
try {
$result = $tableRestProxy->queryEntities("<table>", $user_input);
}
catch(ServiceException $e){
echo "<h1>Error querying, please contact Admin.</h1>";
die();
}
$entities = $result->getEntities();
foreach($entities as $entity){
echo $entity;
}
?>
I have censored out all the connection and table information. But everything works when I use the demo code. But I want to retrieve the full row. When I execute this I get this error
Catchable fatal error: Object of class MicrosoftAzure\Storage\Table\Models\Entity could not be converted to string
Any ideas?
Generally speaking, you are trying to echo an object which raised this issue. As the $entity in your looping statement is an object, you cannot directly echo it.
The queryEntities() returns QueryEntitiesResult object, and then you call getEntities() function which returns Entity objects in array.
So you can use functions $entity->getXXXX() or $entity->getPropertyValue({key}) to get the properties in your table storage's entity.
You can refer to a simple sample for a quick glance.