PHP code example of ekolotech / database-importer

1. Go to this page and download the library: Download ekolotech/database-importer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ekolotech / database-importer example snippets


interface SourceToDestinationDatabaseCommandConfig
{
    public function getSource(): Database;
    public function getDestination(): Database;
}

interface ExportDatabaseCommandConfig
{
    public function getSource(): Database;
}

interface ImportDatabaseCommandConfig
{
    public function getDestination(): Database;
}

class Database
{
    public function __construct(
        string $name, // Nom de la base
        string $host, // le host du serveur
        string $user, // l'utilisateur sur lequel se connecter
        string $password, // le mot de passe de l'utilisateur
    )
    {
    }
}



use DatabaseImporter\Argv;
use DatabaseImporter\CommandHandler;
use DatabaseImporter\model\Database;
use DatabaseImporter\model\ExportDatabaseCommandConfig;
use DatabaseImporter\model\ImportDatabaseCommandConfig;
use DatabaseImporter\model\SourceToDestinationDatabaseCommandConfig;

class ExampleSourceToDestinationDatabaseCommandConfig implements SourceToDestinationDatabaseCommandConfig
{
    public function getSource(): Database
    {
        return new Database(
            "source_database",
            "127.0.0.1",
            "root",
            ""
        );
    }

    public function getDestination(): Database
    {
        return new Database(
            "destination_database",
            "127.0.0.1",
            "root",
            ""
        );
    }
}

class ExampleExportDatabaseCommandConfig implements ExportDatabaseCommandConfig
{
    public function getSource(): Database
    {
        return new Database(
            "source_database",
            "127.0.0.1",
            "root",
            ""
        );
    }
}

class ExampleImportDatabaseCommandConfig implements ImportDatabaseCommandConfig
{
    public function getDestination(): Database
    {
        return new Database(
            "destination_database",
            "127.0.0.1",
            "root",
            ""
        );
    }
}

$commandHandler = new CommandHandler();
$commandHandler->add(new ExampleSourceToDestinationDatabaseCommandConfig());
$commandHandler->add(new ExampleImportDatabaseCommandConfig());
$commandHandler->add(new ExampleExportDatabaseCommandConfig());

try {
    $commandHandler->run(new Argv());
} catch (Exception $e) {
    die($e->getMessage());
}