An open API service indexing awesome lists of open source software.

https://github.com/phpple/altable

Altable用来对通过mysqldump出来的表结构数据进行解析,分析出数据库、数据表、字段、主键、索引等信息。
https://github.com/phpple/altable

Last synced: 4 months ago
JSON representation

Altable用来对通过mysqldump出来的表结构数据进行解析,分析出数据库、数据表、字段、主键、索引等信息。

Awesome Lists containing this project

README

          

Phpple Altable
================

本项目用来对通过mysqldump出来的表结构数据进行解析,分析出数据库、数据表、字段、主键、索引等信息。

[![Latest Stable Version](https://img.shields.io/packagist/v/phpple/altable.svg?style=flat-square)](https://packagist.org/packages/phpple/altable)
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%205.6-8892BF.svg?style=flat-square)](https://php.net/)
[![Build Status](https://img.shields.io/travis/phpple/altable/master.svg?style=flat-square)](https://travis-ci.org/phpple/altable)
[![codecov](https://codecov.io/gh/phpple/altable/branch/master/graph/badge.svg)](https://codecov.io/gh/phpple/altable)

## 使用步骤

composer引入项目
```bash
composer require phpple/altable
```

通过mysqldump导出需要的表结构:
```bash
mysqldump --all-databases --no-data > dump.sql
```

编写php脚本分析数据库结构
```php
dbFilters = [
// 整个库不予分析
'mysql' => null,
// foo.bar不予分析
'foo' => ['bar'],
];
$dbs = $parser->parse(__DIR__.'/dump.sql');

// 开始进行分析
foreach($dbs as $db) {
foreach($db->tables as $table) {
foreach($table->fields as $field) {
if ($field->name == 'uid') {
echo "`{$db->name}`.`{$table->name}` found uid field";
}
}
}
}

// 通过名称查找名称为foo的DB
$parser->find($dbs, 'foo');

// 通过名称查找名称为foo.bar的Table
$parser->find($dbs, 'foo', 'bar');

// 通过名称查找表foo.bar里的字段uid
$parser->find($dbs, 'foo', 'bar', 'uid');
```