0

我正在使用 Ubuntu 12.04 + PHP + Nginx + MySQL 5.6

我的项目路径是 /usr/share/nginx/www/project1

我已经成功安装了 Sphinx 并且能够连接完整的 API。但我喜欢使用 SphinxQL 查询生成器。

我不熟悉作曲家和 php 命名空间。我已经在我的机器上安装了作曲家。

我将“SphinxQL-Query-Builder-master”文件夹复制到我的项目根目录。

现在我执行了这个

use Foolz\SphinxQL\SphinxQL;
use Foolz\SphinxQL\Connection;

// create a SphinxQL Connection object to use with SphinxQL
$conn = new Connection();
$conn->setParams(array('host' => 'domain.tld', 'port' => 9306));

$query = SphinxQL::create($conn)->select('column_one', 'colume_two')
->from('index_ancient', 'index_main', 'index_delta')
    ->match('comment', 'my opinion is superior to yours')
    ->where('banned', '=', 1);

$result = $query->execute();

这返回给我致命错误:找不到类'Foolz\SphinxQL\Connection'

任何人都可以帮助我一步一步地指导这个吗?

谢谢!!

4

1 回答 1

6

Composer 本身不是您的项目的要求,它是 php 包管理器。您可以使用以下命令安装 Foolz\SphinxQL 库:

php composer.phar require foolz/sphinxql-query-builder

如果您的项目文件夹中不存在composer.phar ,您可以使用以下命令下载它:

php -r "readfile('https://getcomposer.org/installer');" | php

成功安装后,SphinxQL 库将下载到供应商文件夹。您还需要要求 composer vendor/autoload.php生成的自动加载脚本,并在使用前更改主机/端口配置。

最后,您的代码示例应如下所示:

require "vendor/autoload.php";
use Foolz\SphinxQL\SphinxQL;
use Foolz\SphinxQL\Connection;

// create a SphinxQL Connection object to use with SphinxQL
$conn = new Connection();
// Here sphinx installation host and port listening for Mysql connection 
$conn->setParams(array('host' => '127.0.0.1', 'port' => 9306));

$query = SphinxQL::create($conn)->select('column_one', 'colume_two')
    ->from('index_ancient', 'index_main', 'index_delta')
    ->match('comment', 'my opinion is superior to yours')
    ->where('banned', '=', 1);

$result = $query->execute();
于 2015-05-14T13:04:09.907 回答