當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。