$config = new ConfigIni('config.ini');
[database] host = localhost username = root password = "" dbname = "mydb" $config = new ConfigIni('config.ini'); $db_config = $config->database; $pdo = new PDO( "mysql:host={$db_config->host};dbname={$db_config->dbname}", $db_config->username, $db_config->password );
[database] host = localhost username = root password = "" dbname = "mydb" [production] ; these settings will override the settings in the [database] section host = myproductiondb.example.com username = produser password = prodpass dbname = "productiondb" $config = new ConfigIni('config.ini'); if (getenv('ENVIRONMENT') == 'production') { $config->mergeSection('production'); } $db_config = $config->database; $pdo = new PDO( "mysql:host={$db_config->host};dbname={$db_config->dbname}", $db_config->username, $db_config->password );In this example, the package library Config ini is used to add environment-specific configuration settings to a database connection. It first loads the default configuration settings from the config.ini file. If the PHP script is being executed in a production environment (determined by the ENVIRONMENT environment variable), it overrides the default settings with the production settings defined in the [production] section of the configuration file. The package library being used here is Config ini.