本文整理汇总了PHP中yii\db\Migration::createTable方法的典型用法代码示例。如果您正苦于以下问题:PHP Migration::createTable方法的具体用法?PHP Migration::createTable怎么用?PHP Migration::createTable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\db\Migration
的用法示例。
在下文中一共展示了Migration::createTable方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createTable
/**
* @inheritdoc
*/
public function createTable($table, $columns, $options = null)
{
if ($options === null && $this->db->driverName === 'mysql') {
$options = sprintf('CHARACTER SET %s COLLATE %s ENGINE=%s ROW_FORMAT=%s', $this->config['charset'], $this->config['collate'], $this->config['engine'], $this->config['row-format']);
}
if (isset($columns['schema']) && is_array($columns['schema'])) {
parent::createTable($table, $columns['schema'], $options);
if (isset($columns['pkey'])) {
$this->addPrimaryKey('pkey', $table, $columns['pkey']);
}
if (isset($columns['pkeys'])) {
foreach ($columns['pkeys'] as $name => $cols) {
$this->addPrimaryKey($name, $table, $cols);
}
}
if (isset($columns['indexes'])) {
foreach ($columns['indexes'] as $name => $cols) {
$this->createIndex($name, $table, $cols);
}
}
if (isset($columns['uniques'])) {
foreach ($columns['uniques'] as $name => $cols) {
$this->createIndex($name, $table, $cols, true);
}
}
if (isset($columns['fkeys'])) {
foreach ($columns['fkeys'] as $name => $config) {
$this->addForeignKey($name, $table, $config['from'], $config['to'][0], $config['to'][1], isset($config['delete']) ? $config['delete'] : null, isset($config['update']) ? $config['update'] : null);
}
}
} else {
parent::createTable($table, $columns, $options);
}
}
示例2: createTable
/**
* @inheritdoc
*/
public function createTable($table, $columns, $options = null)
{
if ($options === null && $this->db->driverName === 'mysql') {
$options = "CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB";
}
parent::createTable($table, $columns, $options);
}
示例3: migrateUp
/**
* @param Migration $migration
* @param string $tableName
*/
public static function migrateUp($migration, $tableName = '{{%files}}')
{
$tableOptions = null;
if ($migration->db->driverName === 'mysql') {
$tableOptions = 'ENGINE=InnoDB CHARSET=utf8';
}
$migration->createTable($tableName, ['id' => Schema::TYPE_PK, 'original_name' => Schema::TYPE_STRING, 'file_size' => Schema::TYPE_INTEGER, 'created_at' => Schema::TYPE_DATETIME, 'updated_at' => Schema::TYPE_DATETIME]);
}
示例4: createTable
/**
* @inheritdoc
*/
public function createTable($name, $columns, $options = null)
{
$baseTableName = $this->db->getSchema()->getRawTableName($name);
if ($this->db->getSchema()->getTableSchema($baseTableName, true) !== null) {
echo " > table {$name} already exists ...\n";
return;
}
parent::createTable($name, $columns, $options);
}
示例5: install
public function install()
{
parent::install();
$migration = new Migration();
$migration->createTable($this->getTable(), ['id' => Schema::TYPE_PK, 'object_id' => Schema::TYPE_INTEGER, 'term_id' => Schema::TYPE_BIGINT, 'value' => Schema::TYPE_STRING]);
if ($migration->db->driverName === 'mysql') {
$migration->addForeignKey('fk_' . $this->getTable() . '_' . $this->getRefTableName(), $this->getTable(), 'object_id', $this->getRefTableName(), 'id', 'CASCADE');
$migration->addForeignKey('fk_' . $this->getTable() . '_' . TaxonomyTerms::tableName(), $this->getTable(), 'term_id', TaxonomyTerms::tableName(), 'id', 'CASCADE');
}
}
示例6: createTable
/**
* @inheritdoc
*/
public function createTable($table, $columns, $options = null)
{
if (is_null($options) && in_array($this->getDb()->getDriverName(), ['mysql', 'mysqli'])) {
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
$options = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
}
foreach ($columns as $name => $type) {
$columns[$name] = $this->fixColumnType($type);
}
parent::createTable($table, $columns, $options);
}
示例7: runCreateTable
/**
* Create table in database
*/
public function runCreateTable()
{
$this->dropTable();
if ($this->hideMigrationOutput) {
ob_start();
}
/** @var Connection $_conn */
$_conn = Yii::$app->{$this->db};
if (!$_conn->schema->getTableSchema($this->tableName)) {
$this->migrationClass->createTable($this->tableNameRaw, $this->columns);
if (is_array($this->primaryKeys) && sizeof($this->primaryKeys)) {
try {
$this->migrationClass->addPrimaryKey("{$this->tableNameRaw}_pk", $this->tableNameRaw, $this->primaryKeys);
} catch (\yii\db\Exception $exp) {
}
}
}
if ($this->hideMigrationOutput) {
ob_clean();
ob_flush();
}
}
示例8: actionTableusercompany
function actionTableusercompany()
{
$id_company = "FIELD1";
$company_name = "FIELD2";
$company_logo = "FIELD3";
$company_color = "FIELD4";
$company_image = "FIELD5";
$migration = new Migration();
$query = $migration->createTable('TABLE34', [$id_company => 'pk', $company_name => 'string', $company_logo => 'string', $company_color => 'string', $company_image => 'string']);
}
示例9: afterSave
/**
* @param bool $insert
* @param array $changedAttributes
* @return bool
*/
public function afterSave($insert, $changedAttributes)
{
parent::afterSave($insert, $changedAttributes);
if ($insert) {
$migrate = new Migration();
$tableOptions = '';
if ($migrate->db->driverName === 'mysql') {
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
}
$table = self::getTable($this->tab_index, $this->tab);
$tableOptions = $tableOptions . " COMMENT '" . Yii::t('app', 'Comment prefix') . $this->name . "'";
$migrate->createTable($table, ['id' => $migrate->primaryKey()], $tableOptions);
return true;
}
}
示例10: createTable
/**
* @inheritdoc
* Notes:
* - table will be auto pefixied if [[$autoWrapTableNames]] is true.
* - options will be auto set by character set and collate for mysql db.
*/
public function createTable($table, $columns, $options = null)
{
if ($options === null && $this->db->driverName === 'mysql') {
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
$charset = $this->db->charset;
$collate = $charset . '_unicode_ci';
$options = "CHARACTER SET {$charset} COLLATE {$collate} ENGINE=InnoDB";
}
$table = $this->autoWrappedTableName($table);
return parent::createTable($table, $columns, $options);
}
示例11: createTable
/**
* @inheritdoc
*/
public function createTable($table, $columns, $options = null)
{
parent::createTable($table, $columns, $options === null ? $this->getTableOptions() : $options);
}