MySQL query to get column names?

To get the column names of a table in MySQL, you can use the SHOW COLUMNS FROM command.

SHOW COLUMNS FROM my_table;

This will return a result set containing the column names of the my_table table.

Watch a course Learn object oriented PHP

You can also use the DESCRIBE command to get the same information:

DESCRIBE my_table;

Both of these commands will return a result set with the following columns:

  • Field: the name of the column
  • Type: the data type of the column
  • Null: whether the column allows NULL values
  • Key: the type of index used for the column (if any)
  • Default: the default value for the column
  • Extra: any additional information about the column (such as whether it is AUTO_INCREMENT)