我正在尝试以编程方式检索MySQL表的注释.向我建议的第一种方法是:
$shown = $db->query('show create table ' . TABLE_NAME)->fetch_row();
preg_match("/COMMENT='(.*)'/", $shown[0], $m);
$comment = $m[1];
Run Code Online (Sandbox Code Playgroud)
但这种解决方法让我感到畏缩.我偶然发现了另一种方式:
$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];
Run Code Online (Sandbox Code Playgroud)
它有点好(没有字符串解析),但它仍然让我感到不舒服,因为我正在挖掘内部结构,我不觉得自己属于.
有没有一个很好的,简单的方法来获取代码中的表注释?