Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $host = "192.168.104.1xxx3";
- $port = 3306;
- $user = "xxxx";
- $password="xxx";
- $dbname = "xx";
- $table = "xxx";
- $db = new PDO("mysql:host={$host};port={$port};dbname={$dbname};charset=UTF8;", $user,$password, array(PDO::ATTR_PERSISTENT=>true));
- $db->query("SET NAMES utf8;");
- $sql = "SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = '{$dbname}' AND TABLE_NAME='{$table}'";
- $rows = $db->query($sql, PDO::FETCH_ASSOC)->fetchAll();
- $commentsMap = [];
- foreach ($rows as $row) {
- $commentsMap[$row['COLUMN_NAME']] = $row['COLUMN_COMMENT'];
- }
- $rows = $db->query('DESC ins_vm', PDO::FETCH_ASSOC)->fetchAll();
- echo "字段,类型,允许 NULL,默认值,描述".PHP_EOL;
- foreach ($rows as $row) {
- echo $row['Field'].",".$row['Type'].",".$row['Null'].",".$row['Default'].",".$commentsMap[$row['Field']].PHP_EOL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement