PHP Класс yii\sphinx\Connection

This class uses PDO to maintain such connection. Note: although PDO supports numerous database drivers, this class supports only MySQL. In order to setup Sphinx "searchd" to support MySQL protocol following configuration should be added: searchd { listen = localhost:9306:mysql41 ... } The following example shows how to create a Connection instance and establish the Sphinx connection: php $connection = new \yii\db\Connection([ 'dsn' => 'mysql:host=127.0.0.1;port=9306;', 'username' => $username, 'password' => $password, ]); $connection->open(); After the Sphinx connection is established, one can execute SQL statements like the following: php $command = $connection->createCommand("SELECT * FROM idx_article WHERE MATCH('programming')"); $articles = $command->queryAll(); $command = $connection->createCommand('UPDATE idx_article SET status=2 WHERE id=1'); $command->execute(); For more information about how to perform various DB queries, please refer to Command. This class supports transactions exactly as "yii\db\Connection". Note: while this class extends "yii\db\Connection" some of its methods are not supported.
С версии: 2.0
Автор: Paul Klimov ([email protected])
Наследование: extends yii\db\Connection
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$enableFloatConversion whether to enable conversion of the float query params into the direct literal SQL insertion. This allows processing of the float values, since PDO does not provide specific param type for float binding, while Sphinx is unable to process float values passed as quoted strings.
$schemaMap

Открытые методы

Метод Описание
createCommand ( string $sql = null, array $params = [] ) : Command Creates a command for execution.
escapeMatchValue ( string $str ) : string Escapes all special characters from 'MATCH' statement argument.
getIndexSchema ( string $name, boolean $refresh = false ) : IndexSchema Obtains the schema information for the named index.
getLastInsertID ( string $sequenceName = '' ) : string This method is not supported by Sphinx.
quoteIndexName ( string $name ) : string Quotes a index name for use in a query.
quoteTableName ( string $name ) : string Alias of Connection::quoteIndexName.

Описание методов

createCommand() публичный Метод

Creates a command for execution.
public createCommand ( string $sql = null, array $params = [] ) : Command
$sql string the SQL statement to be executed
$params array the parameters to be bound to the SQL statement
Результат Command the Sphinx command

escapeMatchValue() публичный Метод

Make sure you are using this method whenever composing 'MATCH' search statement. Note: this method does not perform quoting, you should place the result in the quotes an perform additional escaping for it manually, the best way to do it is using PDO parameter.
public escapeMatchValue ( string $str ) : string
$str string string to be escaped.
Результат string the properly escaped string.

getIndexSchema() публичный Метод

Obtains the schema information for the named index.
public getIndexSchema ( string $name, boolean $refresh = false ) : IndexSchema
$name string index name.
$refresh boolean whether to reload the table schema even if it is found in the cache.
Результат IndexSchema index schema information. Null if the named index does not exist.

getLastInsertID() публичный Метод

This method is not supported by Sphinx.
public getLastInsertID ( string $sequenceName = '' ) : string
$sequenceName string name of the sequence object
Результат string the row ID of the last row inserted, or the last value retrieved from the sequence object

quoteIndexName() публичный Метод

If the index name contains schema prefix, the prefix will also be properly quoted. If the index name is already quoted or contains special characters including '(', '[[' and '{{', then this method will do nothing.
public quoteIndexName ( string $name ) : string
$name string index name
Результат string the properly quoted index name

quoteTableName() публичный Метод

public quoteTableName ( string $name ) : string
$name string table name
Результат string the properly quoted table name

Описание свойств

$enableFloatConversion публичное свойство

whether to enable conversion of the float query params into the direct literal SQL insertion. This allows processing of the float values, since PDO does not provide specific param type for float binding, while Sphinx is unable to process float values passed as quoted strings.
С версии: 2.0.6
public $enableFloatConversion

$schemaMap публичное свойство

public $schemaMap