Class yii\sphinx\Command

Inheritanceyii\sphinx\Command » yii\db\Command
Available since version2.0

Command represents a SQL statement to be executed against a Sphinx.

A command object is usually created by calling yii\sphinx\Connection::createCommand(). The SQL statement it represents can be set via the \yii\sphinx\sql property.

To execute a non-query SQL (such as INSERT, REPLACE, DELETE, UPDATE), call \yii\sphinx\execute(). To execute a SQL statement that returns result data set (such as SELECT, CALL SNIPPETS, CALL KEYWORDS), use \yii\sphinx\queryAll(), \yii\sphinx\queryOne(), \yii\sphinx\queryColumn(), \yii\sphinx\queryScalar(), or \yii\sphinx\query(). For example,

$articles = $connection->createCommand("SELECT * FROM `idx_article` WHERE MATCH('programming')")->queryAll();

Command supports SQL statement preparation and parameter binding just as \yii\db\Command does.

Command also supports building SQL statements by providing methods such as \yii\sphinx\insert(), update(), etc. For example,

$connection->createCommand()->update('idx_article', [
    'genre_id' => 15,
    'author_id' => 157,
])->execute();

To build SELECT SQL statements, please use yii\sphinx\Query and yii\sphinx\QueryBuilder instead.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$db yii\sphinx\Connection The Sphinx connection that this command is associated with. yii\sphinx\Command

Property Details

$db public property

The Sphinx connection that this command is associated with.

public yii\sphinx\Connection $db null

Method Details

addColumn() public method

public void addColumn ( $table, $column, $type )
$table
$column
$type
addForeignKey() public method

public void addForeignKey ( $name, $table, $columns, $refTable, $refColumns, $delete null, $update null )
$name
$table
$columns
$refTable
$refColumns
$delete
$update
addPrimaryKey() public method

public void addPrimaryKey ( $name, $table, $columns )
$name
$table
$columns
alterColumn() public method

public void alterColumn ( $table, $column, $type )
$table
$column
$type
batchInsert() public method

Creates a batch INSERT command.

For example,

$connection->createCommand()->batchInsert('idx_user', ['name', 'age'], [
    ['Tom', 30],
    ['Jane', 20],
    ['Linda', 25],
])->execute();

Note that the values in each row must match the corresponding column names.

public $this batchInsert ( $index, $columns, $rows )
$index string

The index that new rows will be inserted into.

$columns array

The column names

$rows array

The rows to be batch inserted into the index

return $this

The command object itself

batchReplace() public method

Creates a batch REPLACE command.

For example,

$connection->createCommand()->batchReplace('idx_user', ['name', 'age'], [
    ['Tom', 30],
    ['Jane', 20],
    ['Linda', 25],
])->execute();

Note that the values in each row must match the corresponding column names.

public $this batchReplace ( $index, $columns, $rows )
$index string

The index that new rows will be replaced.

$columns array

The column names

$rows array

The rows to be batch replaced in the index

return $this

The command object itself

bindValue() public method

public void bindValue ( $name, $value, $dataType null )
$name
$value
$dataType
bindValues() public method

public void bindValues ( $values )
$values
callKeywords() public method

Returns tokenized and normalized forms of the keywords, and, optionally, keyword statistics.

public $this callKeywords ( $index, $text, $fetchStatistic false )
$index string

The name of the index from which to take the text processing settings

$text string

The text to break down to keywords.

$fetchStatistic boolean

Whether to return document and hit occurrence statistics

return $this

The command object itself

callSnippets() public method

Builds a snippet from provided data and query, using specified index settings.

public $this callSnippets ( $index, $source, $match, $options = [] )
$index string

Name of the index, from which to take the text processing settings.

$source string|array

Is the source data to extract a snippet from. It could be either a single string or array of strings.

$match string

The full-text query to build snippets for.

$options array

List of options in format: optionName => optionValue

return $this

The command object itself

checkIntegrity() public method

public void checkIntegrity ( $check true, $schema '', $table '' )
$check
$schema
$table
createIndex() public method

public void createIndex ( $name, $table, $columns, $unique false )
$name
$table
$columns
$unique
createTable() public method

public void createTable ( $table, $columns, $options null )
$table
$columns
$options
dropColumn() public method

public void dropColumn ( $table, $column )
$table
$column
dropForeignKey() public method

public void dropForeignKey ( $name, $table )
$name
$table
dropIndex() public method

public void dropIndex ( $name, $table )
$name
$table
dropPrimaryKey() public method

public void dropPrimaryKey ( $name, $table )
$name
$table
dropTable() public method

public void dropTable ( $table )
$table
getRawSql() public method

public void getRawSql ( )
prepare() public method

public void prepare ( $forRead null )
$forRead
renameColumn() public method

public void renameColumn ( $table, $oldName, $newName )
$table
$oldName
$newName
renameTable() public method

public void renameTable ( $table, $newName )
$table
$newName
replace() public method

Creates an REPLACE command.

For example,

$connection->createCommand()->replace('idx_user', [
    'name' => 'Sam',
    'age' => 30,
])->execute();

The method will properly escape the column names, and bind the values to be replaced.

Note that the created command is not executed until \yii\sphinx\execute() is called.

public $this replace ( $index, $columns )
$index string

The index that new rows will be replaced into.

$columns array

The column data (name => value) to be replaced into the index.

return $this

The command object itself

resetSequence() public method

public void resetSequence ( $table, $value null )
$table
$value
truncateIndex() public method

Creates a SQL command for truncating a runtime index.

public $this truncateIndex ( $index )
$index string

The index to be truncated. The name will be properly quoted by the method.

return $this

The command object itself

truncateTable() public method

public void truncateTable ( $table )
$table
update() public method

Creates an UPDATE command.

For example,

$connection->createCommand()->update('user', ['status' => 1], 'age > 30')->execute();

The method will properly escape the column names and bind the values to be updated.

Note that the created command is not executed until \yii\sphinx\execute() is called.

public $this update ( $index, $columns, $condition '', $params = [], $options = [] )
$index string

The index to be updated.

$columns array

The column data (name => value) to be updated.

$condition string|array

The condition that will be put in the WHERE part. Please refer to yii\sphinx\Query::where() on how to specify condition.

$params array

The parameters to be bound to the command

$options array

List of options in format: optionName => optionValue

return $this

The command object itself