public function GdprDatabaseManager::fetchColumnNames in General Data Protection Regulation 8
Same name and namespace in other branches
- 8.2 modules/gdpr_dump/src/Service/GdprDatabaseManager.php \Drupal\gdpr_dump\Service\GdprDatabaseManager::fetchColumnNames()
- 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 87
Class
- GdprDatabaseManager
- Class GdprDatabaseManager.
Namespace
Drupal\gdpr_dump\ServiceCode
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));
}