开发者

Access MySQL field's Comments with PHP

When you are creating a field in a MySQL table, ther开发者_运维技巧e's a 'Comments' box to fill out. How can I access the data in that 'Comments' box with PHP?


Use:

SHOW FULL COLUMNS FROM tbl_name

Notice keyword FULL, this is what makes MySQL to include privileges and comments info into the response.


Poke around information_schema.

SELECT table_comment
FROM information_schema.tables
WHERE table_schema = 'myschema' AND table_name = 'mytable'


SELECT 
    COLUMN_COMMENT
FROM 
    information_schema.COLUMNS
WHERE
    TABLE_NAME = 'venue'

Great to use for table column headings or more readable/secure version of real column names. Ex., The column for Venue ID is actually vid_xt

Sample Result from actual query above:

COLUMN_COMMENT
Venue ID
Venue Active
Venue Name
Location Name
Address
Accommodations
Description


Ah, wow. So that's what information_schema database is for. Thank you @Adam Backstrom! Then I believe below should give me the field's comments.

SELECT COLUMN_COMMENT
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = 'mydatabase' AND TABLE_NAME = 'mytable' AND COLUMN_NAME = 'mycolumn'

Thank you for pointing me to the right direction. :-)


I discovered that the following query does the trick for me:

select column_comment from information_schema.columns 
where table_schema = "YOUR_SCHEMA" 
and table_name = "YOUR_TABLE";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜