# Configurations

## Creating a configuration

    /** @var $configuration OpenCloud\Database\Resource\Configuration **/
    $configuration = $service->configuration();

    $configuration->create(array(
        'name'        => 'example-configuration-name',
        'description' => 'An example configuration',
        'values'      => array(
            'collation_server' => 'latin1_swedish_ci',
            'connect_timeout' => 120
        ),
        'datastore' => array(
            'type'    => '10000000-0000-0000-0000-000000000001',
            'version' => '1379cc8b-4bc5-4c4a-9e9d-7a9ad27c0866'
        )
    ));

Get the executable PHP script for this example

## Listing configurations

You can list out all the configurations you have created as shown below:

    $configurations = $service->configurationList();
    foreach ($configurations as $configuration) {
        /** @var $configuration OpenCloud\Database\Resource\Configuration **/
    }

Get the executable PHP script for this example

## Retrieving a configuration

You can retrieve a specific configuration, using its ID, as shown below:

    $configuration = $service->configuration('{configId}');
    /** @var OpenCloud\Database\Resource\Configuration **/

Get the executable PHP script for this example

## Updating a configuration

You have two choices when updating a configuration:

- you can patch a configuration to change only

some configuration parameters * you can entirely replace a configuration to replace all configuration parameters with new ones

### Patching a configuration

You can patch a configuration as shown below:

    $configuration->patch(array(
        'values' => array(
            'connect_timeout' => 30
        )
    ));

Get the executable PHP script for this example

### Replacing a configuration

You can replace a configuration as shown below:

    $configuration->update(array(
        'values' => array(
            'collation_server' => 'utf8_general_ci',
            'connect_timeout' => 60
        )
    ));

Get the executable PHP script for this example

## Deleting a configuration

    $configuration->delete();

Get the executable PHP script for this example

Note

You cannot delete a configuration if it is in use by a running instance.

## Listing instances using a configuration

You can list all instances using a specific configuration, using its ID, as shown below:

    $instances = $configuration->instanceList();
    foreach ($instances as $instance) {
        /** @var $instance OpenCloud\Database\Resource\Instance **/
    }

Get the executable PHP script for this example