Question
How to get database table column names on drupal 8 ?
To get database table columns names of a mysql database you can use "DESCRIBE my_table;" method.
Example: get columns of the table 'node'$con = \Drupal\Core\Database\Database::getConnection();
$fields = $con->query("DESCRIBE `node`")->fetchAll();
var_dump($fields);
For the new database versions you can use INFORMATION_SCHEMA (Not tested) Like:
SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'my_database' AND TABLE_NAME = 'my_table';
Comments
Using Drush
We can use drush as well.
drush sql-query "describe node"
Add new comment