PHP 针对人大金仓KingbaseES自动生成数据字典

针对国产数据库 人大金仓KingbaseES  其实php 连接采用pdo方式

必须:需要去人大数据金仓官方网站 下载对应版本的pdo_kdb 扩展驱动

其连接方法与pgsql 数据库连接方法大致相同    不解释  直接上代码:

setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
    die("连接失败: " . $e->getMessage());
}

$result = $conn->query("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'");
$tables = $result->fetchAll(PDO::FETCH_ASSOC);

$html = '';

$html .= '';
$html .= '';

foreach ($tables as $k => $v) {
    $sort = $k + 1;
    $tableName = $v['table_name'];

    // Get table comment
    $tableComment = $conn->query("SELECT obj_description('public.{$tableName}'::regclass, 'pg_class') AS table_comment")->fetchColumn();

    $html .= '';
    $html .= '';
    $html .= '';
    $html .= '';
    $html .= '';
}
$html .= '
序号表名功能说明
' . $sort . '' . $tableName . '' . $tableComment . '

'; $html .= "


"; foreach ($tables as $v) { $tableName = $v['table_name']; $fields = $conn->query(" SELECT column_name, data_type, column_default, is_nullable, character_maximum_length, -- Add this line if you want to get the character maximum length numeric_precision, -- Add this line if you want to get the numeric precision numeric_scale, -- Add this line if you want to get the numeric scale (SELECT description FROM pg_description WHERE objoid = (SELECT oid FROM pg_class WHERE relname = '{$tableName}' AND relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = 'public')) AND objsubid = (SELECT ordinal_position FROM information_schema.columns WHERE table_name = '{$tableName}' AND table_schema = 'public' AND column_name = c.column_name) ) AS column_comment FROM information_schema.columns c WHERE table_name = '{$tableName}' AND table_schema = 'public' ")->fetchAll(PDO::FETCH_ASSOC); $html .= ''; $html .= ''; $html .= ''; foreach ($fields as $f) { $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; } $html .= '
表名:' . $tableName . ' ' . '
字段名数据类型默认值允许非空备注
' . $f['column_name'] . '' . $f['data_type'] . '' . $f['column_default'] . '' . ($f['is_nullable'] == 'YES' ? '是' : '否') . '' . $f['column_comment'] . '

'; } echo ' 自动生成数据字典 '; echo '

' . $database['DB_NAME'] . '数据字典

'; echo '

生成时间:' . date('Y-m-d H:i:s', time()) . '

'; echo $html; echo '

总共:' . count($tables) . '个数据表

'; echo ''; ?>

你可能感兴趣的:(php,开发语言)