2017 © Pedro Peláez
 

library 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.

image

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.

  • Thursday, December 3, 2015
  • by yuriy-sorokin
  • Repository
  • 1 Watchers
  • 0 Stars
  • 8 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Database data exporter/importer

License Latest Stable Version Total Downloads, (*1)

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., (*2)

It is better to use a DI container to ease the usage of the package., (*3)

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., (*4)

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., (*5)

The test database dump is located in dump.sql.gz., (*6)

The Versions

03/12 2015

dev-master

9999999-dev

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

  Sources   Download

MIT

The Development Requires

by Iurii Sorokin

03/12 2015

2.0.0

2.0.0.0

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

  Sources   Download

MIT

The Development Requires

by Iurii Sorokin

26/11 2015

1.1.0

1.1.0.0

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

  Sources   Download

MIT

The Development Requires

by Iurii Sorokin

26/11 2015

1.0.0

1.0.0.0

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

  Sources   Download

MIT

The Development Requires

by Iurii Sorokin