使用 PHP 访问 MySQL 字段的注释
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5097973/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Access MySQL field's Comments with PHP
提问by penetra
When you are creating a field in a MySQL table, there's a 'Comments' box to fill out. How can I access the data in that 'Comments' box with PHP?
当您在 MySQL 表中创建字段时,需要填写一个“评论”框。如何使用 PHP 访问“评论”框中的数据?
采纳答案by Annika Backstrom
Poke around information_schema
.
四处看看information_schema
。
SELECT table_comment
FROM information_schema.tables
WHERE table_schema = 'myschema' AND table_name = 'mytable'
回答by jayarjo
Use:
用:
SHOW FULL COLUMNS FROM tbl_name
Notice keyword FULL, this is what makes MySQL to include privileges and comments info into the response.
注意关键字FULL,这使 MySQL 在响应中包含权限和注释信息。
回答by Beta Projects
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
非常适合用于表格列标题或更易读/安全的真实列名版本。例如,Venue ID 列实际上是 vid_xt
Sample Result from actual query above:
上面实际查询的示例结果:
COLUMN_COMMENT
Venue ID
Venue Active
Venue Name
Location Name
Address
Accommodations
Description
回答by penetra
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.
啊,哇。这就是 information_schema 数据库的用途。谢谢@Adam Backstrom!然后我相信下面应该给我字段的评论。
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. :-)
感谢您为我指明正确的方向。:-)
回答by Alex
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";
select column_comment from information_schema.columns where table_schema = "YOUR_SCHEMA" and table_name = "YOUR_TABLE";