469,602 Members | 1,699 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,602 developers. It's quick & easy.

retrieving table comment from mysql database

Hi Gurus

Is there a way to retrieve the table comment from a mysql table.

In PHP My Admin, you can set the comment for a table. however, I was
wondering if you can retrieve it for use in a PHP page.

Any help greatly appreciated.

- Nicolaas
Jul 23 '05 #1
5 1890
windandwaves wrote:
Hi Gurus

Is there a way to retrieve the table comment from a mysql table.

In PHP My Admin, you can set the comment for a table. however, I was
wondering if you can retrieve it for use in a PHP page.

Any help greatly appreciated.


Comment saved in a PHP_My_Admin table.
Jul 23 '05 #2
>Is there a way to retrieve the table comment from a mysql table.

In PHP My Admin, you can set the comment for a table. however, I was
wondering if you can retrieve it for use in a PHP page.

Any help greatly appreciated.


In PHP 5.0.x, it's in information_schema.tables.table_comment .

It's also in SHOW CREATE TABLE in PHP 5.0.x and earlier versions.

Gordon L. Burditt
Jul 23 '05 #3
NC
windandwaves wrote:

Is there a way to retrieve the table comment from
a mysql table.


Yes. Run a SHOW CREATE TABLE query on the table you want
to see the comment for. For example, if you have a table
called `example`, the query will be:

SHOW CREATE TABLE example;

It will return a CREATE TABLE statement for the table,
which will include the comment. You will need to parse
it out of the CREATE TABLE statement.

Cheers,
NC

Jul 23 '05 #4
NC wrote:
windandwaves wrote:

Is there a way to retrieve the table comment from
a mysql table.


Yes. Run a SHOW CREATE TABLE query on the table you want
to see the comment for. For example, if you have a table
called `example`, the query will be:

SHOW CREATE TABLE example;

It will return a CREATE TABLE statement for the table,
which will include the comment. You will need to parse
it out of the CREATE TABLE statement.


Thank you for clarifying this.

- Nicolaas
Jul 23 '05 #5
windandwaves wrote:
Hi Gurus

Is there a way to retrieve the table comment from a mysql table.

In PHP My Admin, you can set the comment for a table. however, I was
wondering if you can retrieve it for use in a PHP page.

Any help greatly appreciated.

- Nicolaas


This is the function I made up (I only use one space as indent):

function table_description($t) {
$sql = 'SHOW CREATE TABLE `'.$t.'`;';
$query = mysql_query($sql);
$v = mysql_result($query, 0, 1);
if($v) {
$p = strpos($v,"COMMENT=");
if($p) {
return substr($v, $p + 8);
}
}
return 'Table description not found';
}
Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Bert Sierra | last post: by
3 posts views Thread by Oliver Kohll | last post: by
reply views Thread by guiromero | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.