|
@@ -62,6 +62,33 @@ trait TraitDatabase
|
|
|
return $tables;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取表的备注
|
|
|
+ *
|
|
|
+ * @param string $table 表名
|
|
|
+ * @param string $database 数据库名称
|
|
|
+ * @return array|mixed
|
|
|
+ */
|
|
|
+ public function getTableComment($table, $database = null) {
|
|
|
+ $sql = "
|
|
|
+ SELECT TABLE_NAME AS table, TABLE_COMMENT AS comment
|
|
|
+ FROM INFORMATION_SCHEMA.TABLES
|
|
|
+ WHERE TABLE_SCHEMA = '{$database}'";
|
|
|
+ if($table != '') {
|
|
|
+ $sql .= " AND TABLE_NAME = '{$table}'";
|
|
|
+ }
|
|
|
+
|
|
|
+ $rs = $this->setQuery($sql);
|
|
|
+ $comment = array();
|
|
|
+ while ($row = $rs->fetch()) {
|
|
|
+ $comment[$row['table_name']] = $row['comment'];
|
|
|
+ }
|
|
|
+
|
|
|
+ if($table != '' && isset($comment[$table])) {
|
|
|
+ return $comment[$table];
|
|
|
+ }
|
|
|
+ return $comment;
|
|
|
+ }
|
|
|
/**
|
|
|
* 获取指定数据表的所有字段
|
|
|
* @param string $table 表名
|
|
@@ -196,6 +223,9 @@ trait TraitDatabase
|
|
|
public function getValueFromBrackets($str)
|
|
|
{
|
|
|
preg_match("/(?:\()(.*)(?:\))/i", $str, $matches);
|
|
|
+ if(!$matches) {
|
|
|
+ return $str;
|
|
|
+ }
|
|
|
$str = $matches[1];
|
|
|
$a = explode(",", $str);
|
|
|
for ($i = 0; $i < count($a); $i++) {
|