https://github.com/phpple/altable
Altable用来对通过mysqldump出来的表结构数据进行解析,分析出数据库、数据表、字段、主键、索引等信息。
https://github.com/phpple/altable
Last synced: 4 months ago
JSON representation
Altable用来对通过mysqldump出来的表结构数据进行解析,分析出数据库、数据表、字段、主键、索引等信息。
- Host: GitHub
- URL: https://github.com/phpple/altable
- Owner: phpple
- License: mit
- Created: 2018-08-30T03:27:49.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2021-12-03T04:45:01.000Z (over 4 years ago)
- Last Synced: 2025-07-26T07:40:33.537Z (10 months ago)
- Language: PHP
- Homepage:
- Size: 22.5 KB
- Stars: 7
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
- License: LICENSE
Awesome Lists containing this project
README
Phpple Altable
================
本项目用来对通过mysqldump出来的表结构数据进行解析,分析出数据库、数据表、字段、主键、索引等信息。
[](https://packagist.org/packages/phpple/altable)
[](https://php.net/)
[](https://travis-ci.org/phpple/altable)
[](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');
```