PHP Class 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.
Since: 2.0
Author: Paul Klimov ([email protected])
Inheritance: extends yii\db\Connection
Mostrar archivo Open project: yiisoft/yii2-sphinx Class Usage Examples

Public Properties

Property Type Description
$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

Public Methods

Method Description
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.

Method Details

createCommand() public method

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
return Command the Sphinx command

escapeMatchValue() public method

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.
return string the properly escaped string.

getIndexSchema() public method

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.
return IndexSchema index schema information. Null if the named index does not exist.

getLastInsertID() public method

This method is not supported by Sphinx.
public getLastInsertID ( string $sequenceName = '' ) : string
$sequenceName string name of the sequence object
return string the row ID of the last row inserted, or the last value retrieved from the sequence object

quoteIndexName() public method

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
return string the properly quoted index name

quoteTableName() public method

public quoteTableName ( string $name ) : string
$name string table name
return string the properly quoted table name

Property Details

$enableFloatConversion public_oe property

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.
Since: 2.0.6
public $enableFloatConversion

$schemaMap public_oe property

public $schemaMap