从MySQL表回显字段名到网页


Echo name of fields from MySQL table to web page

当我只知道表名时,如何显示从MySQL表到网页的所有字段名?

使用information_schema元数据库:

SELECT COLUMN_NAME
FROM information_schema.TABLES
WHERE (TABLE_SCHEMA='Yourdb') AND (TABLE_NAME = 'Yourtablename')

除了@MarcB的建议,你还可以这样做:

SHOW COLUMNS FROM table
http://dev.mysql.com/doc/refman/5.6/en/show-columns.html