Settings.php $databases example improvement

Created on 28 January 2010, over 14 years ago
Updated 30 January 2023, over 1 year ago

Problem/Motivation

The documentation in default.settings.php for Drupal 8 shows the following example for a database configuration:

$databases['default']['default'] = array(
    'driver' => 'mysql',
    'database' => 'databasename',
    'username' => 'username',
    'password' => 'password',
    'host' => 'localhost',
    'prefix' => 'main_',
    'collation' => 'utf8_general_ci',
 );

But the actual configuration is created as:

$databases['default']['default'] = array (
  'database' => 'databasename',
  'username' => 'username',
  'password' => 'password',
  'prefix' => '',
  'host' => 'localhost',
  'port' => '3306',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' => 'mysql',
);

The current issue is that the order of the options doesn't match the one in the documentation.

Beta phase evaluation

<!--Uncomment the relevant rows for the issue. -->

Allowed in the beta since it is restricted to just documenation change to make it easier to use the setting.php file.

Proposed resolution

Update the documentation in default.settings.php to match the order of the options.

$databases['default']['default'] = array (
  'database' => 'databasename',
  'username' => 'username',
  'password' => 'password',
  'prefix' => '',
  'host' => 'localhost',
  'port' => '3306',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' => 'mysql',
);

Remaining tasks

<!-- See https://drupal.org/core-mentoring/novice-tasks for tips on identifying novice tasks. Delete or add "Novice" from the Novice? column in the table below as appropriate. Uncomment tasks as the issue advances. Update the Complete? column to indicate when they are done, and maybe reference the comment number where they were done. -->

User interface changes

API changes

Original report by @iantresman

Fortunately, Drupal 7 set-up my settings settings.php file correctly. But I would not have been able to work it out from the examples given, which is more complicated than D6. The example is given as:

 * Database configuration format:
 *   $databases['default']['default'] = array(
 *     'driver' => 'mysql',
 *     'database' => 'databasename',
 *     'username' => 'username',
 *     'password' => 'password',
 *     'host' => 'localhost',
 *   );

But the actual configuration shows as follows, which I think is sufficiently different for the non-programmer (ie, shows "array" three times!):

$databases = array (
  'default' => 
  array (
    'default' => 
    array (
      'driver' => 'mysql',
      'database' => 'mydatabase',
      'username' => 'myname',
      'password' => 'mypassword',
      'host' => 'msql.mydomain.com',
      'port' => '',
    ),
  ),
);

I think the example should be very close to the follow, with an explanation of the arrays for programmers:

$databases = array ('default' => array ('default' => array (
      'driver' => 'mysql',
      'database' => 'mydatabase',
      'username' => 'myname',
      'password' => 'mypassword',
      'host' => 'msql.mydomain.com',
      'port' => '',
    ),
  ),
);
📌 Task
Status

Needs work

Version

10.1

Component
Install 

Last updated 2 days ago

No maintainer
Created by

🇬🇧United Kingdom iantresman

Live updates comments and jobs are added and updated live.
  • Needs manual testing

    The change/bugfix cannot be fully demonstrated by automated testing, and thus requires manual testing in a variety of environments.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

Production build 0.71.5 2024