本文整理汇总了PHP中yii\db\Migration::createIndex方法的典型用法代码示例。如果您正苦于以下问题:PHP Migration::createIndex方法的具体用法?PHP Migration::createIndex怎么用?PHP Migration::createIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\db\Migration
的用法示例。
在下文中一共展示了Migration::createIndex方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createIndex
public function createIndex($name, $table, $columns, $unique = false)
{
if (is_null($name)) {
$name = self::formIndexName($table, $columns, $unique ? "unq" : "idx");
}
return parent::createIndex($name, $table, $columns, $unique);
}
示例2: createIndex
/**
* Builds and executes a SQL statement for creating a new index.
* @param string $name the name of the index. The name will be properly quoted by the method.
* @param string $table the table that the new index will be created for. The table name will be properly quoted by the method.
* @param string $column the column(s) that should be included in the index. If there are multiple columns, please separate them
* by commas or use an array. The column names will be properly quoted by the method.
* @param boolean $unique whether to add UNIQUE constraint on the created index.
*/
public function createIndex($name, $table, $column, $unique = false)
{
if (in_array($this->db->getDriverName(), array('mysql', 'mysqli')) && $table != strtolower($table)) {
echo " > create (via alter table)" . ($unique ? ' unique' : '') . " index {$name} on {$table} (" . implode(',', (array) $column) . ") ...";
$time = microtime(true);
$sql = 'ALTER TABLE ' . $this->db->quoteTableName($table) . ' ADD ' . ($unique ? 'UNIQUE INDEX' : 'INDEX') . ' ' . $this->db->quoteTableName($name) . ' (' . $this->db->getQueryBuilder()->buildColumns($column) . ')';
$this->db->createCommand($sql)->execute();
echo " done (time: " . sprintf('%.3f', microtime(true) - $time) . "s)\n";
} else {
parent::createIndex($name, $table, $column, $unique);
}
}
示例3: createIndex
/**
* @inheritdoc
* Note: table will be auto pefixied if [[$autoWrapTableNames]] is true.
*/
public function createIndex($name, $table, $columns, $unique = false)
{
$table = $this->autoWrappedTableName($table);
return parent::createIndex($name, $table, $columns, $unique);
}
示例4: createIndex
/**
* @inheritdoc
* @param string|null $name
*/
public function createIndex($name, $table, $columns, $unique = false)
{
if (is_null($name)) {
$name = implode('-', (array) $columns);
}
parent::createIndex($name, $table, $columns, $unique);
}
示例5: createIndex
/**
* Builds and executes a SQL statement for creating a new index.
* @param string $name the name of the index. The name will be properly quoted by the method.
* @param string $table the table that the new index will be created for. The table name will be properly quoted by the method.
* @param string|array $columns the column(s) that should be included in the index. If there are multiple columns, please separate them
* by commas or use an array. Each column name will be properly quoted by the method. Quoting will be skipped for column names that
* include a left parenthesis "(".
* @param boolean $unique whether to add UNIQUE constraint on the created index.
*/
public function createIndex($table, $columns, $unique = false, $name = null)
{
$name = $name ?: $this->getNameIndex($table, $columns);
parent::createIndex($name, $table, $columns, $unique);
}