php通过sql生成一个数据库的字段说明的markdown文档,支持mysql,postgresql

技术 置顶 精帖
0 469
peng49
peng49 2023-07-12 18:03:35
 

通过Sql语句生成markdown文档的php程序

安装

composer require peng49/db2markdown

命令行使用

php vendor/bin/db2markdown

输入数据库的 地址(host), 端口(port) 用户名,密码,要导出的表,默认是*,生成所有表的文档,指定多个表明用逗号隔开,如: table1,table2

  1. $ php src/bin/db2markdown
  2. please enter the db(1 mysql,2 postgresql):
  3. please enter the host(localhost):
  4. please enter the port(3306): 3310
  5. please enter username(root):
  6. please enter password: password
  7. please enter database: acg
  8. please enter tables(default is *,match all table):
  9. admin_menu successful
  10. admin_operation_log successful
  11. admin_permissions successful
  12. ....
  13. E:\develop\db2markdown\db2markdown20230712091813.md is export success

导出PostgreSQL结构

  1. $ php src/bin/db2markdown
  2. please enter the db(1 mysql,2 postgresql): 3
  3. please enter the db(1 mysql,2 postgresql): 2
  4. please enter the host(localhost):
  5. please enter the port(5432): 5432
  6. please enter username(root): odoo
  7. please enter password: password
  8. please enter database: gocron
  9. please enter table schema(public):
  10. please enter tables(default is *,match all table):
  11. task successful
  12. task_log successful
  13. host successful
  14. ......
  15. E:\develop\db2markdown\db2markdown20230712092030.md is export success
代码中使用
  1. <?php
  2. require_once "vendor/autoload.php";
  3. /* @var $generator \DB2Markdown\Generator\Mysql */
  4. $generator = \DB2Markdown\Factory::getGenerator('mysql');
  5. //mysql
  6. $generator->setHost('localhost')
  7. ->setPort(3306)
  8. ->setDatabase('database')
  9. ->setUsername('username')
  10. ->setPassword('password')
  11. ->output("filename", "*");
回帖
登录
忘记密码?