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