当前位置: 首页>>代码示例>>PHP>>正文


PHP Migration::createTable方法代码示例

本文整理汇总了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);
     }
 }
开发者ID:cookyii,项目名称:base,代码行数:37,代码来源:Migration.php

示例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);
 }
开发者ID:VeerUP,项目名称:rest-service,代码行数:10,代码来源:Migration.php

示例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]);
 }
开发者ID:omnilight,项目名称:yii2-models,代码行数:12,代码来源:FileMigration.php

示例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);
 }
开发者ID:vipantonio,项目名称:yii2-firebirddb,代码行数:12,代码来源:FirebirdMigration.php

示例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');
     }
 }
开发者ID:traykovn,项目名称:yii2-taxonomy,代码行数:10,代码来源:PropertyTerm.php

示例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);
 }
开发者ID:ivan-chkv,项目名称:yii2-boost,代码行数:14,代码来源:Migration.php

示例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();
     }
 }
开发者ID:infinitydevphp,项目名称:yii2-table-builder,代码行数:25,代码来源:TableBuilder.php

示例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']);
 }
开发者ID:agungsuprayitno,项目名称:sme,代码行数:10,代码来源:QueryController.php

示例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;
     }
 }
开发者ID:jackieit,项目名称:aimocms,代码行数:20,代码来源:Cm.php

示例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);
 }
开发者ID:flexibuild,项目名称:migrate,代码行数:17,代码来源:Migration.php

示例11: createTable

 /**
  * @inheritdoc
  */
 public function createTable($table, $columns, $options = null)
 {
     parent::createTable($table, $columns, $options === null ? $this->getTableOptions() : $options);
 }
开发者ID:skoro,项目名称:yii2-admin-template,代码行数:7,代码来源:Migration.php


注:本文中的yii\db\Migration::createTable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。