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.
Afficher le fichier
Open project: yiisoft/yii2-sphinx
Class Usage Examples
Méthodes publiques
Свойство |
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 |
|
|
|
Méthodes publiques
Method Details
createCommand()
public méthode
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 |
Résultat |
Command |
the Sphinx command |
escapeMatchValue()
public méthode
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.
getIndexSchema()
public méthode
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. |
Résultat |
IndexSchema |
index schema information. Null if the named index does not exist. |
getLastInsertID()
public méthode
This method is not supported by Sphinx.
public getLastInsertID ( string $sequenceName = '' ) : string |
$sequenceName |
string |
name of the sequence object |
Résultat |
string |
the row ID of the last row inserted, or the last value retrieved from the sequence object |
quoteIndexName()
public méthode
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.
quoteTableName()
public méthode
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.
public $enableFloatConversion |
$schemaMap public_oe property