![](/img/trans.png)
[英]What would be most elegant way to replicate data contents periodically into a MySQL table?
[英]What's the most elegant way to retrieve a MySQL table comment?
我正在嘗試以編程方式檢索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];
它有點好(沒有字符串解析),但它仍然讓我感到不舒服,因為我正在挖掘內部結構,我覺得我不屬於自己。
有沒有一個很好的,簡單的方法來獲取代碼中的表注釋?
信息模式實際上不是您不屬於的內部結構。 它是ANSI SQL標准的一部分,其目的是為您提供查詢元數據的合法方式。
我會毫不猶豫地使用它。
一個缺點是MySQL的信息架構實現往往具有相當差的性能 。 所以要小心在應該快速的例程中對IS運行查詢。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.