Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access MySQL field's Comments with PHP

Tags:

php

mysql

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?

like image 621
penetra Avatar asked Feb 23 '11 22:02

penetra


People also ask

How can you retrieve data from the MySQL database using PHP?

Data can be fetched from MySQL tables by executing SQL SELECT statement through PHP function mysql_query. You have several options to fetch data from MySQL. The most frequently used option is to use function mysql_fetch_array(). This function returns row as an associative array, a numeric array, or both.

How do I view comments in MySQL?

In MySQL, you can create a SQL comment that spans multiple lines in your SQL statement. For example: SELECT contact_id, last_name, first_name /* * Author: TechOnTheNet.com * Purpose: To show a comment that spans multiple lines in your SQL * statement in MySQL.


4 Answers

Poke around information_schema.

SELECT table_comment
FROM information_schema.tables
WHERE table_schema = 'myschema' AND table_name = 'mytable'
like image 41
Annika Backstrom Avatar answered Sep 23 '22 19:09

Annika Backstrom


Use:

SHOW FULL COLUMNS FROM tbl_name

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

like image 169
jayarjo Avatar answered Sep 23 '22 19:09

jayarjo


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
like image 8
Beta Projects Avatar answered Sep 25 '22 19:09

Beta Projects


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. :-)

like image 6
penetra Avatar answered Sep 22 '22 19:09

penetra