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


PHP Connection::databaseType方法代码示例

本文整理汇总了PHP中Drupal\Core\Database\Connection::databaseType方法的典型用法代码示例。如果您正苦于以下问题:PHP Connection::databaseType方法的具体用法?PHP Connection::databaseType怎么用?PHP Connection::databaseType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Database\Connection的用法示例。


在下文中一共展示了Connection::databaseType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1:

 /**
  * Construct the database dump command.
  *
  * @param \Drupal\Core\Database\Connection $connection
  *   The database connection to use.
  * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
  *   The module handler to use.
  */
 function __construct(Connection $connection, ModuleHandlerInterface $module_handler)
 {
     // Check this is MySQL.
     if ($connection->databaseType() !== 'mysql') {
         throw new \RuntimeException('This script can only be used with MySQL database backends.');
     }
     $this->connection = $connection;
     $this->moduleHandler = $module_handler;
     parent::__construct();
 }
开发者ID:jeyram,项目名称:camp-gdl,代码行数:18,代码来源:DbDumpCommand.php

示例2: getTableSchema

 /**
  * Returns a schema array for a given table.
  *
  * @param \Drupal\Core\Database\Connection $connection
  *   The database connection to use.
  * @param string $table
  *   The table name.
  *
  * @return array
  *   A schema array (as defined by hook_schema()).
  *
  * @todo This implementation is hard-coded for MySQL.
  */
 protected function getTableSchema(Connection $connection, $table)
 {
     // Check this is MySQL.
     if ($connection->databaseType() !== 'mysql') {
         throw new \RuntimeException('This script can only be used with MySQL database backends.');
     }
     $query = $connection->query("SHOW FULL COLUMNS FROM {" . $table . "}");
     $definition = [];
     while (($row = $query->fetchAssoc()) !== FALSE) {
         $name = $row['Field'];
         // Parse out the field type and meta information.
         preg_match('@([a-z]+)(?:\\((\\d+)(?:,(\\d+))?\\))?\\s*(unsigned)?@', $row['Type'], $matches);
         $type = $this->fieldTypeMap($connection, $matches[1]);
         if ($row['Extra'] === 'auto_increment') {
             // If this is an auto increment, then the type is 'serial'.
             $type = 'serial';
         }
         $definition['fields'][$name] = ['type' => $type, 'not null' => $row['Null'] === 'NO'];
         if ($size = $this->fieldSizeMap($connection, $matches[1])) {
             $definition['fields'][$name]['size'] = $size;
         }
         if (isset($matches[2]) && $type === 'numeric') {
             // Add precision and scale.
             $definition['fields'][$name]['precision'] = $matches[2];
             $definition['fields'][$name]['scale'] = $matches[3];
         } elseif ($type === 'time' || $type === 'datetime') {
             // @todo Core doesn't support these, but copied from `migrate-db.sh` for now.
             // Convert to varchar.
             $definition['fields'][$name]['type'] = 'varchar';
             $definition['fields'][$name]['length'] = '100';
         } elseif (!isset($definition['fields'][$name]['size'])) {
             // Try use the provided length, if it doesn't exist default to 100. It's
             // not great but good enough for our dumps at this point.
             $definition['fields'][$name]['length'] = isset($matches[2]) ? $matches[2] : 100;
         }
         if (isset($row['Default'])) {
             $definition['fields'][$name]['default'] = $row['Default'];
         }
         if (isset($matches[4])) {
             $definition['fields'][$name]['unsigned'] = TRUE;
         }
         // Check for the 'varchar_ascii' type that should be 'binary'.
         if (isset($row['Collation']) && $row['Collation'] == 'ascii_bin') {
             $definition['fields'][$name]['type'] = 'varchar_ascii';
             $definition['fields'][$name]['binary'] = TRUE;
         }
         // Check for the non-binary 'varchar_ascii'.
         if (isset($row['Collation']) && $row['Collation'] == 'ascii_general_ci') {
             $definition['fields'][$name]['type'] = 'varchar_ascii';
         }
         // Check for the 'utf8_bin' collation.
         if (isset($row['Collation']) && $row['Collation'] == 'utf8_bin') {
             $definition['fields'][$name]['binary'] = TRUE;
         }
     }
     // Set primary key, unique keys, and indexes.
     $this->getTableIndexes($connection, $table, $definition);
     // Set table collation.
     $this->getTableCollation($connection, $table, $definition);
     return $definition;
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:74,代码来源:DbDumpCommand.php

示例3: fieldsUpdated


//.........这里部分代码省略.........
      // These are new fields that were previously not indexed.
      foreach ($new_fields as $field_id => $field) {
        $reindex = TRUE;
        if (Utility::isTextType($field->getType())) {
          if (!isset($text_table)) {
            // If we have not encountered a text table, assign a name for it.
            $text_table = $this->findFreeTable($prefix . '_', 'text');
          }
          $fields[$field_id]['table'] = $text_table;
        }
        else {
          $fields[$field_id]['table'] = $this->findFreeTable($prefix . '_', $field_id);
          $this->createFieldTable($field, $fields[$field_id]);
        }

        // Always add a column in the denormalized table.
        $fields[$field_id]['column'] = $this->findFreeColumn($denormalized_table, $field_id);
        $this->createFieldTable($field, array('table' => $denormalized_table, 'column' => $fields[$field_id]['column']));

        $fields[$field_id]['type'] = $field->getType();
        $fields[$field_id]['boost'] = $field->getBoost();
      }

      // If needed, make sure the text table exists.
      if (isset($text_table) && !$this->database->schema()->tableExists($text_table)) {
        $table = array(
          'name' => $text_table,
          'module' => 'search_api_db',
          'fields' => array(
            'item_id' => array(
              'type' => 'varchar',
              'length' => 50,
              'description' => 'The primary identifier of the item',
              'not null' => TRUE,
            ),
            'field_name' => array(
              'description' => "The name of the field in which the token appears, or an MD5 hash of the field",
              'not null' => TRUE,
              'type' => 'varchar',
              'length' => 191,
            ),
            'word' => array(
              'description' => 'The text of the indexed token',
              'type' => 'varchar',
              'length' => 50,
              'not null' => TRUE,
            ),
            'score' => array(
              'description' => 'The score associated with this token',
              'type' => 'int',
              'unsigned' => TRUE,
              'not null' => TRUE,
              'default' => 0,
            ),
          ),
          'indexes' => array(
            'word_field' => array(array('word', 20), 'field_name'),
          ),
          // Add a covering index since word is not repeated for each item.
          'primary key' => array('item_id', 'field_name', 'word'),
        );
        $this->database->schema()->createTable($text_table, $table);

        // Some DBMSs will need a character encoding and collation set. Since
        // this largely circumvents Drupal's database layer, but isn't integral
        // enough to fail completely when it doesn't work, we wrap it in a
        // try/catch, to be on the safe side.
        try {
          switch ($this->database->databaseType()) {
            case 'mysql':
              $this->database->query("ALTER TABLE {{$text_table}} CONVERT TO CHARACTER SET 'utf8' COLLATE 'utf8_bin'");
              break;

            case 'pgsql':
              $this->database->query("ALTER TABLE {{$text_table}} ALTER COLUMN word SET DATA TYPE character varying(50) COLLATE \"C\"");
              break;

            // @todo Add fixes for other DBMSs.
            case 'oracle':
            case 'sqlite':
            case 'sqlsrv':
              break;
          }
        }
        catch (\PDOException $e) {
          $vars['%index'] = $index->label();
          watchdog_exception('search_api_db', $e, '%type while trying to change collation for the fulltext table of index %index: @message in %function (line %line of %file).', $vars);
        }
      }

      $this->getKeyValueStore()->set($index->id(), $db_info);

      return $reindex;
    }
      // The database operations might throw PDO or other exceptions, so we catch
      // them all and re-wrap them appropriately.
    catch (\Exception $e) {
      throw new SearchApiException($e->getMessage(), $e->getCode(), $e);
    }
  }
开发者ID:jkyto,项目名称:agolf,代码行数:101,代码来源:Database.php


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