You are here

public function GdprDatabaseManager::fetchColumnNames in General Data Protection Regulation 8.2

Same name and namespace in other branches
  1. 8 modules/gdpr_dump/src/Service/GdprDatabaseManager.php \Drupal\gdpr_dump\Service\GdprDatabaseManager::fetchColumnNames()
  2. 3.0.x modules/gdpr_dump/src/Service/GdprDatabaseManager.php \Drupal\gdpr_dump\Service\GdprDatabaseManager::fetchColumnNames()

Get the column names for a table as an array.

Parameters

string $table: The table name.

Return value

array The columns.

Throws

\Drupal\Core\Database\InvalidQueryException

File

modules/gdpr_dump/src/Service/GdprDatabaseManager.php, line 89

Class

GdprDatabaseManager
Class GdprDatabaseManager.

Namespace

Drupal\gdpr_dump\Service

Code

public function fetchColumnNames($table) {
  $query = $this->database
    ->select('information_schema.columns', 'columns');
  $query
    ->fields('columns', [
    'COLUMN_NAME',
  ]);
  $query
    ->condition('TABLE_SCHEMA', $this->database
    ->getConnectionOptions()['database']);
  $query
    ->condition('TABLE_NAME', $table);
  $result = $query
    ->execute();
  if (NULL === $result) {
    throw new InvalidQueryException("Columns for '{$table}' not available.");
  }
  return array_keys($result
    ->fetchAllAssoc('COLUMN_NAME', PDO::FETCH_ASSOC));
}