The db_config model is used to establish a database connection with an SQL database. To create a connection object you need to provide the connection string which identifies the database you want to connect to and well as a valid user id and password that is authorized to access the database.

Let's review the parameters of a db_config definition.

db_config Parameters

Connection String

The connection string identifies the database server, host name and database name. The exact format and contents of the connection string are database specific. Consult your database documentation for details related to the connection string you should use.

DBMS Adapter

Each database platform has certain nuances or differences in the way it supports or processes SQL commands. The DBMS adapter is intended to handle these database specific rules so that developers can work with different SQL databases in a generic way. Adapters are implemented as PHP classes and are normally stored in the system pseudo site under the classes\dbms_adapter folder.

User Name

Enter a user name that has been configured within the database you wish to access.

Password

Enter the password associated with the User Name above.

Encrypt

By default, passwords are stored in plain text within the generated config file. This means that anyone who has access to this file could discover the user name and password required to connect to the database. By checking the Encrypt option, the password will be stored as an encrypted value so that the actual password is not revealed in the generated code.

Permitted Environments

In most cases you will want to connect to a different database depending on what environment you are executing in. Check all of the environments that are permitted to connect to the database you are configuring. If you want to take a database out of service temporarily you could uncheck all of these environment flags and after promoting this db_config file to production the database would not be accessible.

Database Driver Options

This grid is used to supply any options that you would like to set to configure the database. Both the Attribute value and the setting value can reference PDO constants or hard-coded text or numerical values.

The following settings are used by default but can be overridden by supplying alternate settings:

PDO::ATTR_ERRMODE = PDO::ERRMODE_EXCEPTION; // Trap errors by default
PDO::ATTR_DEFAULT_FETCH_MODE = PDO::FETCH_ASSOC; // Don't fetch assoc and column numbers by default
PDO::ATTR_EMULATE_PREPARES = false; // Don't emulate prepares by default

Adding Databases to Schemas

Use the schema model to define which database should be used in each environment. The schema model refers to the definitions created using the db_config model.

Sample db_config definition
🡇
Sample db_config connection