What's the most elegant way to retrieve a MySQL table comment?

I'm trying to programmatically retrieve the comment for a MySQL table. The first method suggested to me was:

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

But that kind of workaround makes me cringe. I stumbled upon another way:

$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];

It's a little better (no string parsing), but it still makes me uncomfortable because I'm digging into internal structures where I don't feel like I belong.

Is there a nice, simple way to get at the table comment in code?

5
задан zildjohn01 20 August 2010 в 18:18
поделиться