MySQL query to get column names?

前端 未结 21 2189
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 01:56

I\'d like to get all of a mysql table\'s col names into an array in php?

Is there a query for this?

21条回答
  •  误落风尘
    2020-11-22 02:44

    This query fetches a list of all columns in a database without having to specify a table name. It returns a list of only column names:

    SELECT COLUMN_NAME
      FROM INFORMATION_SCHEMA.COLUMNS
      WHERE table_schema = 'db_name'
    

    However, when I ran this query in phpmyadmin, it displayed a series of errors. Nonetheless, it worked. So use it with caution.

提交回复
热议问题