What is the most elegant way to get a comment on a MySQL table?

I am trying to programmatically get a comment for a MySQL table. The first method suggested to me was as follows:

$shown = $db->query('show create table ' . TABLE_NAME)->fetch_row();
preg_match("/COMMENT='(.*)'/", $shown[0], $m);
$comment = $m[1];

But such a workaround makes me cringe. I came across a different path:

$result = $db->query("select table_comment from information_schema.tables where table_schema = '" .
    DATABASE_NAME . "' and table_name = '" TABLE_NAME '\'')->fetch_row();
$comment = $result[0];

This is a little better (without parsing the string), but it still becomes uncomfortable to me because I dig into internal structures where it doesn't seem to me that I belong.

Is there a good, easy way to get a table comment in code?

+5
source share
1 answer

, . ANSI SQL - .

.

, MySQL . IS , .

+3

All Articles