Laravel/Several databases

From Aimeos documentation

Laravel
Other languages:
English 100%


The Aimeos web shop is able to use different databases for its data domains. Thus, you can configure a separate database e.g. for all customer or order related data. If no specific database is configured for a data domain, the default database will be used.

The default database configuration is defined in the config/shop.php file of the Aimeos shop package and looks like

  1. 'resource' => array
  2.     'db' => array
  3.         'adapter' => 'mysql',
  4.         'host' => '<from .env file>',
  5.         'port' => '',
  6.         'database' => '<from .env file>',
  7.         'username' => '<from .env file>',
  8.         'password' => '<from .env file>',
  9.         'stmt' => array("SET NAMES 'utf8'", "SET SESSION sql_mode='ANSI'"),
  10.         'limit' => 2,
  11.         'opt-persistent' => 0,
  12.     ),
  13. ),

It defines the database location and credentials as well as the default statements that are executed when opening a connection ("stmt"), the maximum allowed connections to this database for the request ("limit") and if the database connection should persist between connections ("opt-persistent"). You can define one database for each domain (e.g. order, customer, etc.) in the same way. To store all orders in a separate database, add another configuration block to your config/shop.php file:

  1. 'resource' => array
  2.     'db-order' => array
  3.         'adapter' => 'mysql',
  4.         'host' => '<hostname or IP address>',
  5.         'port' => '<server port>',
  6.         'database' => '<database name>',
  7.         'username' => '<database user>',
  8.         'password' => '<user password>',
  9.         'stmt' => array("SET NAMES 'utf8'", "SET SESSION sql_mode='ANSI'"),
  10.         'limit' => 2,
  11.         'opt-persistent' => 0,
  12.     ),
  13. ),

The important line contains the db-order key, which tells Aimeos that this resource configuration is for a database that should contain all data from the "order" domain (which includes all mshop_order* tables).

More details about the available domains and the necessary configuration is available in the