PHP code example of zero1 / magento2-splitdb

1. Go to this page and download the library: Download zero1/magento2-splitdb 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/ */

    

zero1 / magento2-splitdb example snippets


'db' => [
    'table_prefix' => '',
    'connection' => [
        'default' => [
            'host' => '[DB_HOST]',
            'dbname' => '[DB_NAME]',
            'username' => '[DB_USERNAME]',
            'password' => '[DB_PASSWORD]',
            'model' => 'mysql4',
            'engine' => 'innodb',
            'initStatements' => 'SET NAMES utf8;',
            'active' => '1',
        ]
    ]
],

'db' => [
    'table_prefix' => '',
    'connection' => [
        'default' => [
            'host' => '[DB_HOST]',
            'dbname' => '[DB_NAME]',
            'username' => '[DB_USERNAME]',
            'password' => '[DB_PASSWORD]',
            'model' => 'mysql4',
            'engine' => 'innodb',
            'initStatements' => 'SET NAMES utf8;',
            'active' => '1',
            'slaves' => [
                [
                    'host' => '[DB_READER_1_HOST]',
                    'username' => '[DB_READER_1_USERNAME]',
                    'password' => '[DB_READER_1_PASSWORD]',
                ],
                [
                    'host' => '[DB_READER_2_HOST]',
                    'username' => '[DB_READER_2_USERNAME]',
                    'password' => '[DB_READER_2_PASSWORD]',
                ]
            ]
        ]
    ]
],

  'db' => [
      'table_prefix' => '',
      'connection' => [
          'default' => [
              'host' => '[DB_HOST]',
              'dbname' => '[DB_NAME]',
              'username' => '[DB_USERNAME]',
              'password' => '[DB_PASSWORD]',
              'model' => 'mysql4',
              'engine' => 'innodb',
              'initStatements' => 'SET NAMES utf8;',
              'active' => '1',
              'excluded_areas' => [],
              'slaves' => [
                  [
                      'host' => '[DB_READER_1_HOST]',
                      'username' => '[DB_READER_1_USERNAME]',
                      'password' => '[DB_READER_1_PASSWORD]',
                  ],
                  [
                      'host' => '[DB_READER_2_HOST]',
                      'username' => '[DB_READER_2_USERNAME]',
                      'password' => '[DB_READER_2_PASSWORD]',
                  ]
              ]
          ]
      ]
  ],
  

  'db' => [
      'table_prefix' => '',
      'connection' => [
          'default' => [
              'host' => '[DB_HOST]',
              'dbname' => '[DB_NAME]',
              'username' => '[DB_USERNAME]',
              'password' => '[DB_PASSWORD]',
              'model' => 'mysql4',
              'engine' => 'innodb',
              'initStatements' => 'SET NAMES utf8;',
              'active' => '1',
              'excluded_areas' => [
                  '/checkout',
                  '/customer',
                  '/another-location',
              ],
              'slaves' => [
                  [
                      'host' => '[DB_READER_1_HOST]',
                      'username' => '[DB_READER_1_USERNAME]',
                      'password' => '[DB_READER_1_PASSWORD]',
                  ],
                  [
                      'host' => '[DB_READER_2_HOST]',
                      'username' => '[DB_READER_2_USERNAME]',
                      'password' => '[DB_READER_2_PASSWORD]',
                  ]
              ]
          ]
      ]
  ],
  

'log_level' => \Monolog\Logger::INFO,