yuriy-sorokin/database-exporter-importer 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

yuriy-sorokin/database-exporter-importer

Composer 安装命令:

composer require yuriy-sorokin/database-exporter-importer

包简介

This package is used to export/import database data to/from different formats. Currently it supports only MySQL database and JSON export/import structure.

README 文档

README

License Latest Stable Version Total Downloads

The purpose of the package is to export/import certain data records from a database. Say, you have a bunch of related DB tables, which represent your user module. So, you want to copy a user with all the related information to another database, which already has tables created.

It is better to use a DI container to ease the usage of the package.

Exporting

<?php
$connection = new \PDO('mysql:dbname=DATABASE_NAME;host=HOST', 'USER', 'PASSWORD');

$columnsProvider = new MySqlTableColumnsProvider($connection);
$tablesProvider = new MySqlTablesProvider($columnsProvider);
$tablesProvider->setConnection($connection);

$dataProvider = new MySqlDataProvider($tablesProvider);
$dataProvider
    ->setConnection($connection)
    ->setForeignValueProvider(new TableForeignKeysValuesProvider())
    ->setPrimaryTableName('maker')
    ->setPrimaryKeyColumn('id')
    ->setPrimaryKey(1);

$exporter = new JsonDataExporter();
$data = $exporter
    ->setColumnsExporter(new JsonTableColumnsExporter())
    ->setDataRowsExporter(new JsonTableDataRowsExporter())
    ->setDataProvider($dataProvider)
    ->getData();

Finally, this $data variable contains a JSON string, which is ready to be imported. Pay attention that auto increment values of the root table are reset while importing.

Importing

<?php
$connection = new \PDO('mysql:dbname=DATABASE_NAME;host=HOST', 'USER', 'PASSWORD');

$dataParser = new JsonDataParser();
$dataParser
    ->setColumnsCreator(new JsonColumnsCreator())
    ->setDataRowsCreator(new JsonDataRowsCreator())
    ->setData($data);

$subject = new MySqlDataImporter();
$subject
    ->setConnection($connection)
    ->setDataParser($dataParser)
    ->setObserver(new AutoIncrementObserver(new ForeignKeyColumnsFinder()))
    ->setAutoIncrementFinder(new AutoIncrementTableColumnFinder())
    ->import();

Currently it supports only MySQL database and JSON export/import structure.

The test database dump is located in dump.sql.gz.

统计信息

  • 总下载量: 24
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-11-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固