Add database connections via wp-config.php
The GWP_DB_CONFIGS
constant allows you to define multiple database connections in your application. Each connection has its own unique settings, such as table names, database names, and optional external connection details. Below is a step-by-step guide on how to configure this constant.
Configuration Structure
Each entry in the GWP_DB_CONFIGS
array represents a separate database connection configuration with the following fields:
- name: The user-friendly name displayed to users.
- table: The name of the table associated with this configuration.
- database: The name of the database where the table resides.
- host (Optional): The external database host if connecting externally.
- username (Optional): The username for accessing an external database.
- password (Optional): The password for accessing an external database.
Configuration Example
Here’s an example setup of the GWP_DB_CONFIGS
constant:
define( 'GWP_DB_CONFIGS', array(
// Internal connection configuration.
array(
'name' => 'Primary Database',
'table' => 'db_table',
'database' => 'db_name',
'host' => '', // Leave empty if not required
'username' => '', // Leave empty if not required
'password' => '', // Leave empty if not required
),
// Connect to External DB server.
array(
'name' => 'External Service DB',
'table' => 'db_table',
'database' => 'db_name',
'host' => 'mysql-2e694f89-minduls-ffc3.e.yourdbprovider.com',
'username' => 'YOURUSERNAME',
'password' => 'YOURPASSWORD',
),
// Connection to Internal DB server.
array(
'name' => 'Internal DB',
'table' => 'db_table',
'database' => 'db_name',
'host' => '192.168.1.10',
'username' => 'user3',
'password' => 'pass3',
),
));