PHP Class yii\sphinx\Command

A command object is usually created by calling [[Connection::createCommand()]]. The SQL statement it represents can be set via the [[sql]] property. To execute a non-query SQL (such as INSERT, REPLACE, DELETE, UPDATE), call [[execute()]]. To execute a SQL statement that returns result data set (such as SELECT, CALL SNIPPETS, CALL KEYWORDS), use [[queryAll()]], [[queryOne()]], [[queryColumn()]], [[queryScalar()]], or [[query()]]. For example, ~~~ $articles = $connection->createCommand("SELECT * FROM idx_article WHERE MATCH('programming')")->queryAll(); ~~~ Command supports SQL statement preparation and parameter binding just as Command does. Command also supports building SQL statements by providing methods such as [[insert()]], Command::update, etc. For example, ~~~ $connection->createCommand()->update('idx_article', [ 'genre_id' => 15, 'author_id' => 157, ])->execute(); ~~~ To build SELECT SQL statements, please use Query and QueryBuilder instead.
Since: 2.0
Author: Paul Klimov ([email protected])
Inheritance: extends yii\db\Command
Mostrar archivo Open project: yiisoft/yii2-sphinx Class Usage Examples

Public Properties

Property Type Description
$db the Sphinx connection that this command is associated with.

Public Methods

Method Description
addColumn ( $table, $column, $type )
addForeignKey ( $name, $table, $columns, $refTable, $refColumns, $delete = null, $update = null )
addPrimaryKey ( $name, $table, $columns )
alterColumn ( $table, $column, $type )
batchInsert ( string $index, array $columns, array $rows ) Creates a batch INSERT command.
batchReplace ( string $index, array $columns, array $rows ) Creates a batch REPLACE command.
bindValue ( $name, $value, $dataType = null )
bindValues ( $values )
callKeywords ( string $index, string $text, boolean $fetchStatistic = false ) Returns tokenized and normalized forms of the keywords, and, optionally, keyword statistics.
callSnippets ( string $index, string | array $source, string $match, array $options = [] ) Builds a snippet from provided data and query, using specified index settings.
checkIntegrity ( $check = true, $schema = '', $table = '' )
createIndex ( $name, $table, $columns, $unique = false )
createTable ( $table, $columns, $options = null )
dropColumn ( $table, $column )
dropForeignKey ( $name, $table )
dropIndex ( $name, $table )
dropPrimaryKey ( $name, $table )
dropTable ( $table )
prepare ( $forRead = null )
renameColumn ( $table, $oldName, $newName )
renameTable ( $table, $newName )
replace ( string $index, array $columns ) Creates an REPLACE command.
resetSequence ( $table, $value = null )
truncateIndex ( string $index ) Creates a SQL command for truncating a runtime index.
truncateTable ( $table )
update ( string $index, array $columns, string | array $condition = '', array $params = [], array $options = [] ) Creates an UPDATE command.

Private Methods

Method Description
parseFloatParams ( string $sql ) : string Parses given SQL replacing bound [[floatParams]] with their values.

Method Details

addColumn() public method

public addColumn ( $table, $column, $type )

addForeignKey() public method

public addForeignKey ( $name, $table, $columns, $refTable, $refColumns, $delete = null, $update = null )

addPrimaryKey() public method

public addPrimaryKey ( $name, $table, $columns )

alterColumn() public method

public alterColumn ( $table, $column, $type )

batchInsert() public method

For example, php $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 batchInsert ( string $index, array $columns, array $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

batchReplace() public method

For example, php $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 batchReplace ( string $index, array $columns, array $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

bindValue() public method

public bindValue ( $name, $value, $dataType = null )

bindValues() public method

public bindValues ( $values )

callKeywords() public method

Returns tokenized and normalized forms of the keywords, and, optionally, keyword statistics.
public callKeywords ( string $index, string $text, boolean $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

callSnippets() public method

Builds a snippet from provided data and query, using specified index settings.
public callSnippets ( string $index, string | array $source, string $match, array $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

checkIntegrity() public method

public checkIntegrity ( $check = true, $schema = '', $table = '' )

createIndex() public method

public createIndex ( $name, $table, $columns, $unique = false )

createTable() public method

public createTable ( $table, $columns, $options = null )

dropColumn() public method

public dropColumn ( $table, $column )

dropForeignKey() public method

public dropForeignKey ( $name, $table )

dropIndex() public method

public dropIndex ( $name, $table )

dropPrimaryKey() public method

public dropPrimaryKey ( $name, $table )

dropTable() public method

public dropTable ( $table )

prepare() public method

public prepare ( $forRead = null )

renameColumn() public method

public renameColumn ( $table, $oldName, $newName )

renameTable() public method

public renameTable ( $table, $newName )

replace() public method

For example, php $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 [[execute()]] is called.
public replace ( string $index, array $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.

resetSequence() public method

public resetSequence ( $table, $value = null )

truncateIndex() public method

Creates a SQL command for truncating a runtime index.
public truncateIndex ( string $index )
$index string the index to be truncated. The name will be properly quoted by the method.

truncateTable() public method

public truncateTable ( $table )

update() public method

For example, php $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 [[execute()]] is called.
public update ( string $index, array $columns, string | array $condition = '', array $params = [], array $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 [[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

Property Details

$db public_oe property

the Sphinx connection that this command is associated with.
public $db