当前位置: 首页 > news >正文

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

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

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

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

<?php
/*** 生成人大金仓数据字典*/
header("Content-type:text/html;charset=utf-8");// 配置数据库
$database = array();
$database['DB_HOST'] = '127.0.0.1';
$database['DB_NAME'] = 'demo';
$database['DB_USER'] = 'demo';
$database['DB_PWD'] = 'demo';
$database['PORT'] = 54321;
try {$conn = new PDO("kdb:host={$database['DB_HOST']};dbname={$database['DB_NAME']};port={$database['PORT']}", $database['DB_USER'], $database['DB_PWD']);$conn->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 .= '<table border="1" cellspacing="0" cellpadding="0" align="center">';
$html .= '<tbody><tr><th>序号</th><th>表名</th><th>功能说明</th></tr>';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 .= '<tr>';$html .= '<td class="c1">' . $sort . '</td>';$html .= '<td class="c2">' . $tableName . '</td>';$html .= '<td class="c3">' . $tableComment . '</td>';$html .= '</tr>';
}
$html .= '</tbody></table></p>';$html .= "<br /><br /><br />";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 lengthnumeric_precision, -- Add this line if you want to get the numeric precisionnumeric_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_commentFROM information_schema.columns cWHERE table_name = '{$tableName}' AND table_schema = 'public'")->fetchAll(PDO::FETCH_ASSOC);$html .= '<table border="1" cellspacing="0" cellpadding="0" align="center">';$html .= '<caption>表名:' . $tableName . ' ' . '</caption>';$html .= '<tbody><tr><th>字段名</th><th>数据类型</th><th>默认值</th><th>允许非空</th><th>备注</th></tr>';foreach ($fields as $f) {$html .= '<tr>';$html .= '<td class="c1">' . $f['column_name'] . '</td>';$html .= '<td class="c2">' . $f['data_type'] . '</td>';$html .= '<td class="c3">' . $f['column_default'] . '</td>';$html .= '<td class="c4">' . ($f['is_nullable'] == 'YES' ? '是' : '否') . '</td>';$html .= '<td class="c5">' . $f['column_comment'] . '</td>';$html .= '</tr>';}$html .= '</tbody></table></p>';
}echo '<html><meta charset="utf-8"><title>自动生成数据字典</title><style>body,td,th {font-family:"宋体"; font-size:12px;}table,h1,p{width:960px;margin:0px auto;}table{border-collapse:collapse;border:1px solid #CCC;background:#efefef;}table caption{text-align:left; background-color:#fff; line-height:2em; font-size:14px; font-weight:bold; }table th{text-align:left; font-weight:bold;height:26px; line-height:26px; font-size:12px; border:1px solid #CCC;padding-left:5px;}table td{height:20px; font-size:12px; border:1px solid #CCC;background-color:#fff;padding-left:5px;}.c1{ width: 150px;}.c2{ width: 150px;}.c3{ width: 80px;}.c4{ width: 100px;}.c5{ width: 300px;}</style><body>';
echo '<h1 style="text-align:center;">' . $database['DB_NAME'] . '数据字典</h1>';
echo '<p style="text-align:center;margin:20px auto;">生成时间:' . date('Y-m-d H:i:s', time()) . '</p>';
echo $html;
echo '<p style="text-align:left;margin:20px auto;">总共:' . count($tables) . '个数据表</p>';
echo '</body></html>';
?>

http://www.lryc.cn/news/246381.html

相关文章:

  • java选择排序和冒泡排序
  • linux反弹shell
  • Go字符串类型
  • DjiTello + YoloV5的无人机的抽烟检测
  • 数据库取多个时间字段的最大值
  • C/C++ 实现Socket交互式服务端
  • kotlin 防范竞态
  • 超分辨率重建
  • 防止恶意攻击,服务器DDoS防御软件科普
  • nint和Pattern matching介绍(C#)
  • 部署jenkins一直显示Please wait while Jenkins is getting ready to work
  • Redis性能压测、监控工具及优化方案
  • 使用NVM管理多个Nodejs版同时本支持vue2、vue3
  • 局域网的网络ip不稳定问题
  • uniapp (vue3)生成二维码
  • Android11编译第八弹:root用户密码设置
  • XML Schema中的attributeFormDefault
  • 数据结构 / 结构体字节计算
  • rancher2.6 docker版本部署
  • UE5人物残影学习(材质实现)
  • Spring Boot 内置工具类
  • C语言--每日选择题--Day27
  • 黑马程序员索引学习笔记
  • 新手如何对一个web网页进行一次渗透测试
  • vs2019 - MFC对话框程序的工程名称不支持下划线命名法
  • java JDBCUtils 使用静态代码块连接数据库 全程值保持一次连接
  • 剑指 Offer(第2版)题解(C++ Version)
  • 6.15合并二叉树(LC617-E)
  • 百度智能小程序系统源码+关键词排名优化 附带完整的搭建教程
  • 2019年11月7日 Go生态洞察:Go Modules v2及更高版本