Php 如何连接到SphinQL查询生成器?
我使用的是Ubuntu 12.04+PHP+Nginx+MySQL 5.6 我的项目路径是/usr/share/nginx/www/project1 我已经成功安装了Sphinx,并且能够连接完整的API。但我喜欢使用SphinxQL查询生成器 我不熟悉composer和php名称空间。我已经在我的机器上安装了composer 我将“SphinxQL查询生成器主”文件夹复制到我的项目根目录中 现在我执行了这个Php 如何连接到SphinQL查询生成器?,php,sphinxql,Php,Sphinxql,我使用的是Ubuntu 12.04+PHP+Nginx+MySQL 5.6 我的项目路径是/usr/share/nginx/www/project1 我已经成功安装了Sphinx,并且能够连接完整的API。但我喜欢使用SphinxQL查询生成器 我不熟悉composer和php名称空间。我已经在我的机器上安装了composer 我将“SphinxQL查询生成器主”文件夹复制到我的项目根目录中 现在我执行了这个 use Foolz\SphinxQL\SphinxQL; use Foolz\Sphi
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();
这将返回我致命错误:找不到类“傻瓜Z\SphinxQL\Connection”
有人能帮我一步一步地做这个指导吗
谢谢 Composer本身并不是您项目的要求,它是php包管理器。您可以使用以下命令安装傻瓜Z\SphinxQL库:
php composer.phar require foolz/sphinxql-query-builder
如果项目文件夹中不存在composer.phar,可以使用以下方法下载:
php -r "readfile('https://getcomposer.org/installer');" | php
成功安装后,SphinxQL库将下载到供应商的文件夹中。此外,您还需要使用composer供应商/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();
Composer本身并不是您项目的要求,它是php包管理器。您可以使用以下命令安装傻瓜Z\SphinxQL库:
php composer.phar require foolz/sphinxql-query-builder
如果项目文件夹中不存在composer.phar,可以使用以下方法下载:
php -r "readfile('https://getcomposer.org/installer');" | php
成功安装后,SphinxQL库将下载到供应商的文件夹中。此外,您还需要使用composer供应商/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();