【发布时间】:2011-04-01 19:30:57
【问题描述】:
我正在尝试以编程方式检索 MySQL 表的注释。向我建议的第一种方法是:
$shown = $db->query('show create table ' . TABLE_NAME)->fetch_row();
preg_match("/COMMENT='(.*)'/", $shown[0], $m);
$comment = $m[1];
但这种解决方法让我感到畏缩。我偶然发现了另一种方式:
$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];
稍微好一点(没有字符串解析),但它仍然让我感到不舒服,因为我正在挖掘我不属于自己的内部结构。
有没有一种很好、简单的方法来获取代码中的表格注释?
【问题讨论】: