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.
파일 보기
프로젝트 열기: yiisoft/yii2-sphinx
1 사용 예제들
공개 프로퍼티들
프로퍼티 |
타입 |
설명 |
|
$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 |
|
|
|
공개 메소드들
메소드 상세
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.
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. |
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 |
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.
프로퍼티 상세
$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.
public $enableFloatConversion |