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

Reference: https://www.drupal.org/core/beta-changes
Issue category Task since it's not really a bug./td>
Issue priority Minor since it is not really cosmetic, but supposed to reduce confusion.
Unfrozen changes Unfrozen since only changes comments.
Prioritized changes The main goal of this issue is usability of the settings.php file
Disruption NOT Disruptive for core/contributed and custom modules/themes because it will not require a BC break/deprecation/internal refactoring/widespread changes...

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

Contributor tasks needed
Task Novice task? Contributor instructions Complete?
Double-check that the format was fixed in Drupal 8 Yes This was mentioned in #698236-53: Settings.php $databases example improvement and #698236-54: Settings.php $databases example improvement Yes
Update the documentation to match the order. Yes The order is: database, username, password, prefix, host, port, namespace and driver Yes
Replace var_export as suggested in #698236-36: Settings.php $databases example improvement #698236-48: Settings.php $databases example improvement asserts that drupal_var_export in not available at install time and according to #698236-71: Settings.php $databases example improvement the suggested function is now Variable::export().
Complete the rest of #698236-64: Settings.php $databases example improvement part 3

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' => '',
    ),
  ),
);

Comments

Anonymous’s picture

Version: 7.x-dev » 8.x-dev
Category: feature » task
Issue tags: +Novice

I agree. Since most people (even non-developers) will have to muddle about in a settings.php file at one time or another, and will most likely have to do it when they are new to Drupal, we should make it as easy as possible to figure out. Specifying the nested arrays in different ways between the comment and the actual implementation is unnecessarily confusing. We should make it consistent.

stixes’s picture

I think the generated code overcomplicates the issue, since all the parenthesis and added syntax reduces readability.
It would make better sense to let the implementation follow the example.

derjochenmeyer’s picture

I aggree with #2 but the output is generated in includes/install.inc:584 drupal_rewrite_settings() using the PHP function var_export(). The output of this function can't be formated differently.

The Drupal function drupal_var_export() returns similar output.

Without writing a custom var_export function we can only rewrite the documentation according to the output of var_export() to make it consistent. But that would dramatically reduce the readability of the documentation.

/**
 * Database settings:
 *
 * The $databases array specifies the database connection or
 * connections that Drupal may use.  Drupal is able to connect
 * to multiple databases, including multiple types of databases,
 * during the same request.
 *
 * Each database connection is specified as an array of settings,
 * similar to the following:
 * @code
 * array(
 *   'driver' => 'mysql',
 *   'database' => 'databasename',
 *   'username' => 'username',
 *   'password' => 'password',
 *   'host' => 'localhost',
 *   'port' => 3306,
 *   'prefix' => 'myprefix_',
 *   'collation' => 'utf8_general_ci',
 * );
 * @endcode
 *
 * The "driver" property indicates what Drupal database driver the
 * connection should use.  This is usually the same as the name of the
 * database type, such as mysql or sqlite, but not always.  The other
 * properties will vary depending on the driver.  For SQLite, you must
 * specify a database file name in a directory that is writable by the
 * webserver.  For most other drivers, you must specify a
 * username, password, host, and database name.
 *
 * Some database engines support transactions.  In order to enable
 * transaction support for a given database, set the 'transactions' key
 * to TRUE.  To disable it, set it to FALSE.  Note that the default value
 * varies by driver.  For MySQL, the default is FALSE since MyISAM tables
 * do not support transactions.
 *
 * For each database, you may optionally specify multiple "target" databases.
 * A target database allows Drupal to try to send certain queries to a
 * different database if it can but fall back to the default connection if not.
 * That is useful for master/slave replication, as Drupal may try to connect
 * to a slave server when appropriate and if one is not available will simply
 * fall back to the single master server.
 *
 * The general format for the $databases array is as follows:
 * @code
 * $databases['default']['default'] = $info_array;
 * $databases['default']['slave'][] = $info_array;
 * $databases['default']['slave'][] = $info_array;
 * $databases['extra']['default'] = $info_array;
 * @endcode
 *
 * In the above example, $info_array is an array of settings described above.
 * The first line sets a "default" database that has one master database
 * (the second level default).  The second and third lines create an array
 * of potential slave databases.  Drupal will select one at random for a given
 * request as needed.  The fourth line creates a new database with a name of
 * "extra".
 *
 * For a single database configuration, the following is sufficient:
 * @code
 * $databases['default']['default'] = array(
 *   'driver' => 'mysql',
 *   'database' => 'databasename',
 *   'username' => 'username',
 *   'password' => 'password',
 *   'host' => 'localhost',
 *   'prefix' => 'main_',
 *   'collation' => 'utf8_general_ci',
 * );
 * @endcode
 *
 * You can optionally set prefixes for some or all database table names
 * by using the 'prefix' setting. If a prefix is specified, the table
 * name will be prepended with its value. Be sure to use valid database
 * characters only, usually alphanumeric and underscore. If no prefixes
 * are desired, leave it as an empty string ''.
 *
 * To have all database names prefixed, set 'prefix' as a string:
 * @code
 *   'prefix' => 'main_',
 * @endcode
 * To provide prefixes for specific tables, set 'prefix' as an array.
 * The array's keys are the table names and the values are the prefixes.
 * The 'default' element is mandatory and holds the prefix for any tables
 * not specified elsewhere in the array. Example:
 * @code
 *   'prefix' => array(
 *     'default'   => 'main_',
 *     'users'     => 'shared_',
 *     'sessions'  => 'shared_',
 *     'role'      => 'shared_',
 *     'authmap'   => 'shared_',
 *   ),
 * @endcode
 * You can also use a reference to a schema/database as a prefix. This maybe
 * useful if your Drupal installation exists in a schema that is not the default
 * or you want to access several databases from the same code base at the same
 * time.
 * Example:
 * @code
 *   'prefix' => array(
 *     'default'   => 'main.',
 *     'users'     => 'shared.',
 *     'sessions'  => 'shared.',
 *     'role'      => 'shared.',
 *     'authmap'   => 'shared.',
 *   );
 * @endcode
 * NOTE: MySQL and SQLite's definition of a schema is a database.
 *
 * Database configuration format:
 * @code
 *   $databases['default']['default'] = array(
 *     'driver' => 'mysql',
 *     'database' => 'databasename',
 *     'username' => 'username',
 *     'password' => 'password',
 *     'host' => 'localhost',
 *     'prefix' => '',
 *   );
 *   $databases['default']['default'] = array(
 *     'driver' => 'pgsql',
 *     'database' => 'databasename',
 *     'username' => 'username',
 *     'password' => 'password',
 *     'host' => 'localhost',
 *     'prefix' => '',
 *   );
 *   $databases['default']['default'] = array(
 *     'driver' => 'sqlite',
 *     'database' => '/path/to/databasefilename',
 *   );
 * @endcode
 */
derjochenmeyer’s picture

Status: Active » Needs review
StatusFileSize
new1.24 KB

Attached patch rewrites output for $databases setting in includes/install.inc:584 drupal_rewrite_settings().

derjochenmeyer’s picture

Added a comment.

derjochenmeyer’s picture

And removed a trailing space.

stixes’s picture

Valid patch that fixes the issue.

xjm’s picture

Status: Needs review » Needs work

Thanks for your work on this patch. Couple questions/remarks:

+++ b/includes/install.incundefined
@@ -623,7 +623,18 @@ function drupal_rewrite_settings($settings = array(), $prefix = '') {
+                $buffer .= '$' . "databases['$db_first_key']['$db_second_key'] = " . var_export($values, TRUE) . ";" . (!empty($setting['comment']) ? ' // ' . $setting['comment'] . "\n" : "\n");
...
+            $buffer .= '$' . $variable[1] . " = " . var_export($setting['value'], TRUE) . ";" . (!empty($setting['comment']) ? ' // ' . $setting['comment'] . "\n" : "\n");

These are sort of hard to read... I'd suggest using a full if/else rather than the ternary, since the lines are long.

Also, is it possible to add an automated test for this behavior? Not sure if we have test coverage for the creation of settings.php or not.

Finally, note that the Drupal 8.x patch will need to be rerolled, because the core directory structure for Drupal 8 has now changed. (For more information, see #22336: Move all core Drupal files under a /core folder to improve usability and upgrades).

It would also help to have somewhat more detailed reviews (rather than simply "fixes the issue."). E.g., some before/after, what you did to test it, etc.

derjochenmeyer’s picture

Status: Needs work » Needs review

These are sort of hard to read... I'd suggest using a full if/else rather than the ternary, since the lines are long.

I agree, but basically the second one is just re-adding the existing code, removed before:

-          $buffer .= '$' . $variable[1] . " = " . var_export($setting['value'], TRUE) . ";" . (!empty($setting['comment']) ? ' // ' . $setting['comment'] . "\n" : "\n");

Maybe we don't even need the comments following the $databases array?

+          if ($variable[1] == 'databases') {
+            foreach($setting['value'] as $db_first_key => $values) {
+              foreach($values as $db_second_key => $values) {
+                $buffer .= '$' . "databases['$db_first_key']['$db_second_key'] = " . var_export($values, TRUE) . ";\n");
+              }
+            }
+          }

Creating tests for this is over my head, I guess. I'd need some help with that.

I'll be happy to reroll the patch, but setting this to "needs review" to get some opinions first.

hosef’s picture

I updated the patch so that it will apply against the current state of Drupal.

While I was doing that I also decided to brake out the two big long lines into full if/else statements. After doing that I realized that I had never seen the output from $setting['comment'], so I did a quick grep to find where else it is used and found that $setting['comment'] is not used in core and it has no purpose, hence I completely removed the part where it adds $setting['comment'] to $buffer.

I would also have written a test to test against this functionality, however I can't figure out how one would actually run the test if this code didn't work in the first place.

hosef’s picture

Assigned: Unassigned » hosef
hosef’s picture

I just want to see how the automated test site handles this. Don't use this on a real install.

Status: Needs review » Needs work

The last submitted patch, improve-databases-settings-documentation-698236-5.patch, failed testing.

hosef’s picture

Ok, it appears that qa.drupal.org already tests to make sure that Drupal can install. Therefore, writing a test against this will duplicate existing functionality(I think?).

xjm’s picture

Component: other » install system
Status: Needs work » Needs review
Issue tags: +Needs manual testing

Thanks @hosef (and thanks also for fixing that ternary). The patch looks clean to me codewise.

@hosef and I discussed this in IRC (regarding what the bot actually tests, etc.) Since we can't test the installer at present, let's do some manual testing for this patch (maybe with each database type?). Include some before/after code snippets of the settings.php from your testing in your review.

Leaving this tagged as "novice" for that task.

hosef’s picture

In the course of trying to figure out what i was supposed to assert in a test, I installed D8 ~30 times, so I already have the code snippets. But, I still need someone else to test it before it should be marked RTBC.

Here is the $databases variable before applying the patch on each of my VM's and after applying the patch on each of my VM's.

MySQL before patch:

$databases = array (
  'default' => 
  array (
    'default' => 
    array (
      'database' => 'testdatabase',
      'username' => 'testuser',
      'password' => 'T3st1ngP4ssw0rd',
      'host' => 'localhost',
      'port' => '',
      'driver' => 'mysql',
      'prefix' => '',
    ),
  ),
);

MySQL after patch:

$databases['default']['default'] = array (
  'database' => 'testdatabase',
  'username' => 'testuser',
  'password' => 'T3st1ngP4ssw0rd',
  'host' => 'localhost',
  'port' => '',
  'driver' => 'mysql',
  'prefix' => '',
);

SQLite before patch:

$databases = array (
  'default' => 
  array (
    'default' => 
    array (
      'database' => 'sites/default/files/.ht4.sqlite',
      'driver' => 'sqlite',
      'prefix' => '',
    ),
  ),
);

SQLite after patch:

$databases['default']['default'] = array (
  'database' => 'sites/default/files/.ht5.sqlite',
  'driver' => 'sqlite',
  'prefix' => '',
);

PostgreSQL before patch:

$databases = array (
  'default' => 
  array (
    'default' => 
    array (
      'database' => 'testdatabase',
      'username' => 'testuser',
      'password' => 'T3st1ngP4ssw0rd',
      'host' => 'localhost',
      'port' => '',
      'driver' => 'pgsql',
      'prefix' => '',
    ),
  ),
);

PostgreSQL after patch:

$databases['default']['default'] = array (
  'database' => 'testdatabase',
  'username' => 'testuser',
  'password' => 'T3st1ngP4ssw0rd',
  'host' => 'localhost',
  'port' => '',
  'driver' => 'pgsql',
  'prefix' => '',
);
xjm’s picture

Excellent, thanks @hosef! That will make it much easier for reviewers to know what to check for.

Zgear’s picture

Assigned: hosef » Zgear

I'll test this in a bit

Zgear’s picture

Assigned: Zgear » Unassigned

Confirmed, the patch does as hosef said. I installed a fresh version of D8 with the patch in, and the settings.php file did include all of the changes.

hosef’s picture

Assigned: Unassigned » hosef

Thanks for the positive review Zgear. There are a few things I would like to point out though.

First, it appears from your comment that you only tested my patch on one of the three supported databases. When there is a patch that could potentially modify how database stuff works, one is supposed to test it on at least MySQL, PostgreSQL, and SQLite. If you have access to another database such as Microsoft SQL server or Oracle server, then it would also be nice for the community to know how well something works with them and where we could make improvements.

Second, the 'Assigned:' drop down box is supposed to be the person who is fixing the problem not the person reviewing the fix. So, in this case even though you were helping by reviewing the patch it was still assigned to me. Assigning an issue to yourself is kind of like saying 'I have an interest in the issue and want to write a patch that fixes it, and/or re-roll existing patches until the patch is committed to core or I un-assign it from myself.'

aimeilian’s picture

Assigned: hosef » aimeilian

Assigning to self for manual review

aimeilian’s picture

Assigned: aimeilian » Unassigned

If I'm reading the comment thread correctly, this issue requires before/after patch testing against the three supported database schemata. I had taken on this task thinking it was simply a documentation review; regrettably I only have MySQL available right now, so I can't actually test the patch in the remaining databases.

That said, being new to Drupal but familiar with PHP, great job on getting documentation and implementation to match.

aimeilian’s picture

De-assigning; kindly forgive if this comment is superfluous!

disasm’s picture

disasm’s picture

MySQL

<?php
$databases['default']['default'] = array (
  'database' => 'drupal8',
  'username' => 'drupal',
  'password' => 'drupal',
  'host' => 'localhost',
  'port' => '',
  'driver' => 'mysql',
  'prefix' => '',
);
?>

SQLite

<?php
$databases['default']['default'] = array (
  'database' => 'sites/default/files/.ht.sqlite',
  'driver' => 'sqlite',
  'prefix' => '',
);
?>

Note on SQLite, the settings.php file was written correctly, however; I did run into some weird errors about watchdog table not existing. I think this is unrelated though, because it gave the same errors when I tried installing pre-patch.

And finally postgresql:

<?php
$databases['default']['default'] = array (
  'database' => 'drupal',
  'username' => 'drupal',
  'password' => 'drupal',
  'host' => 'localhost',
  'port' => '',
  'driver' => 'pgsql',
  'prefix' => '',
);
?>
hosef’s picture

Status: Needs review » Reviewed & tested by the community

Alright, I just tested the rerolled patch, and everything worked. Marking RTBC. I can backport this if we decide that would be good idea.

catch’s picture

Status: Reviewed & tested by the community » Needs work
+          foreach($setting['value'] as $db_first_key => $values) {
+            foreach($values as $db_second_key => $values) {

Can we find better variable names than $db_first_key and $db_second_key? There's also code style issues here i.e. missing a space after the foreach. The array formatting does look friendlier though.

disasm’s picture

Status: Needs work » Needs review
StatusFileSize
new967 bytes
new2.98 KB

reroll and rename db_first_key to db_name and db_second_key to db_role.

derjochenmeyer’s picture

Fixing foreach code style issues.

cferthorney’s picture

Status: Needs review » Needs work

Patch changed file permissions from 644 to 755. Patch rerolled and resubmitted in following commit.

cferthorney’s picture

Status: Needs work » Needs review
StatusFileSize
new2.98 KB

Adjust patch for correct file permissions

star-szr’s picture

star-szr’s picture

This has always confused me, happy to find this issue!

+++ b/core/includes/install.incundefined
@@ -214,7 +214,18 @@ function drupal_rewrite_settings($settings = array()) {
+        // Add special handling for the $databases setting to improve readability and to
+        // match the format of the database settings documentation in settings.php.

This inline comment should wrap at 80 characters per http://drupal.org/node/1354#drupal.

hazem.tamimi’s picture

hazem.tamimi’s picture

damien tournoud’s picture

Status: Needs review » Needs work

This is a cute patch :)

We also need to kill about 90% of the unnecessary text of default.settings.php, but that's another issue.

+          foreach ($setting['value'] as $db_name => $values) {
+            foreach ($values as $db_role => $values) {
+              $buffer .= '$' . "databases['$db_name']['$db_role'] = " . var_export($values, TRUE) . ";";
+            }
+          }

There are a couple of issues in there:

  • We should use drupal_var_export() instead of var_export() here (and in the other branch below) to match our coding standards (especially the spacing after array);
  • The variable needs to be cleared first ($databases = array();), before outputting the sub-keys;
  • The keys ($db_name and $db_roles) should be output using drupal_var_export() too, as in:
    $buffer .= '$databases[' . drupal_var_export($db_name) . '][' . drupal_var_export($db_role) . '] = ' . drupal_var_export($values, TRUE) . ';';
    
petercook’s picture

I applied patch at #31 and ran install first with mysql. The relevant part of settings.php is as follows:

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

Also ran the install with sqlite which gave the following:

$databases['default']['default'] = array (
  'database' => 'sites/default/files/.ht.sqlite',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\sqlite',
  'driver' => 'sqlite',
  'prefix' => '',
);

It seems we now have a value 'namespace' showing up in the settings that isn't in the example.

petercook’s picture

Status: Needs work » Needs review
StatusFileSize
new3.17 KB

Added code to patch #31 so that the 'namespace' values exist in the example code as they do in the settings. Works for mysql, sqlite and postgres. Postgres settings output below:

$databases['default']['default'] = array (
  'database' => 'postgres',
  'username' => 'postgres',
  'password' => 'postgres',
  'host' => 'localhost',
  'port' => '',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\pgsql',
  'driver' => 'pgsql',
  'prefix' => '',
);
yesct’s picture

Status: Needs review » Needs work
Issue tags: +Novice, +Needs manual testing

The last submitted patch, improve_database_settings_documentation-698236-38.patch, failed testing.

sanguis’s picture

Status: Needs work » Needs review
StatusFileSize
new3.45 KB

rerolled patch from #38 against 711dd53

Status: Needs review » Needs work
Issue tags: -Novice, -Needs manual testing

The last submitted patch, improve_database_settings_documentation-698236-41.patch, failed testing.

star-szr’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work
Issue tags: +Novice, +Needs manual testing

The last submitted patch, improve_database_settings_documentation-698236-41.patch, failed testing.

star-szr’s picture

Thanks @sanguis! I diffed the two patches, I don't think the reroll was quite right. Were there many conflicts while rebasing?

sanguis’s picture

there was one but I thought I sorted it. will retry

derjochenmeyer’s picture

Status: Needs work » Needs review
StatusFileSize
new2.85 KB

drupal_rewrite_settings() has been completely rewritten.

In the corresponding issue #1921818: Modify drupal_rewrite_settings() to allow writing $settings values heyrocker also suggests rewriting the dumps of whole arrays in favor of a simplified output as proposed here.

Here's an updated patch.

derjochenmeyer’s picture

drupal_var_export() as suggested in #37 is not available during install.

derjochenmeyer’s picture

StatusFileSize
new2.84 KB

remove whitespace.

star-szr’s picture

Issue tags: -Novice, -Needs manual testing

#49: 698236-49.patch queued for re-testing.

flefle’s picture

Issue tags: +Novice, +Needs manual testing

#49: 698236-49.patch queued for re-testing.

lucastockmann’s picture

Assigned: Unassigned » lucastockmann

Applied patch #49 and tested with MySQL. It worked.

$databases['default']['default'] = array (
  'database' => 'database_name',
  'username' => 'user',
  'password' => 'pass',
  'host' => '127.0.0.1',
  'port' => '',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' => 'mysql',
  'prefix' => '',
);
brahmjeet789’s picture

Issue summary: View changes
StatusFileSize
new137.08 KB

without apply any patch the file all the changes are reflected in setting.php file in drupal-8.x

steeloctopus’s picture

I tested this issue on both drupal-8.x and drupal-7.x. Here are my findings:
drupal-7.x

$databases = array (
  'default' => 
  array (
    'default' => 
    array (
      'database' => 'database_name',
      'username' => 'user',
      'password' => 'pass',
      'host' => 'localhost',
      'port' => '3306',
      'driver' => 'mysql',
      'prefix' => 'drupal_',
    ),
  ),
);

drupal-8.x

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

drupal-8x branch is working as expected but this will need to be resolved on the drupal-7x branch

steeloctopus’s picture

Version: 8.x-dev » 7.x-dev
steeloctopus’s picture

I'm currently working on a back port

steeloctopus’s picture

StatusFileSize
new1.48 KB

The patch has been added to make the database string in an easily read format.

I have tested this locally and it works as expected.

Status: Needs review » Needs work

The last submitted patch, 57: 698236-57.diff, failed testing.

steeloctopus’s picture

Status: Needs work » Needs review

57: 698236-57.diff queued for re-testing.

lucastockmann’s picture

Assigned: lucastockmann » Unassigned

Unassigning..

gaetanpru’s picture

Status: Needs review » Active

Hello,

I'm working with a drupal site on mysql database but i would like to use my other database oracle to display data on my site. But when i configure a new database in settings.php, i have an error : "PDOException: could not find driver in eval() (line 4 of E:\drupal\modules\php\php.module(80) : eval()'d code)."

I have to declare my driver in "Database configuration format" of settings.php too or juste add a new database?

If you have some example how to use a second database (oracle) could you say me?

Thanks

yesct’s picture

Title: D7: Settings.php $databases example improvement » Settings.php $databases example improvement
Version: 7.x-dev » 8.x-dev

There seem to be a few things going on at once here.

Fixes need to be done in 8.x first and then backported to 7.x.
This issue was moved to 8.x in comment #1,
and then moved back to 7.x in #55....
BUT it was never committed to 8.x.

Let's get this ready for 8.x and *then* do the backport.

----
Note on #57, the patch there is not following the coding standards.
https://drupal.org/coding-standards

For example,

+++ b/includes/install.inc
@@ -629,8 +629,25 @@ function drupal_rewrite_settings($settings = array(), $prefix = '') {
+          if ($variable[1] == 'databases')
+          {
+            foreach ($setting['value'] as $db_name => $db_roles)
+            {

The { should not be on it's own line.

@steeloctopus what editor are you using? there maybe be a drupal coding standards file you can import, or you might have to configure your editor settings manually.

-----

Now, back to 8.x.

iantresman’s picture

I still don't think we should be using a programming construct to define the database settings, which forces a novice to content with the correct placement of quotes, assignments, and commas etc. Looking at the option, YAML looks clear, unambiguous, well defined, and easy to use:

This is horrendous:

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

 

YAML is clear:

databases:
   database:  database_name
   username:  user
   password:  pass
   host:      localhost
   port:      3306
   namespace: Drupal\\Core\\Database\\Driver\\mysql
   driver:    mysql
   prefix:    drupal_
yesct’s picture

Status: Active » Needs work

#54 was a manual test of the last 8.x patch from #49.

A review of #49:

1.

+++ b/sites/default/default.settings.php
@@ -64,12 +64,12 @@
  * array(
- *   'driver' => 'mysql',
  *   'database' => 'databasename',
  *   'username' => 'username',
  *   'password' => 'password',
  *   'host' => 'localhost',
  *   'port' => 3306,
+ *   'driver' => 'mysql',

@@ -116,11 +116,11 @@
  * $databases['default']['default'] = array(
- *   'driver' => 'mysql',
  *   'database' => 'databasename',
  *   'username' => 'username',
  *   'password' => 'password',
  *   'host' => 'localhost',
+ *   'driver' => 'mysql',
  *   'prefix' => 'main_',

there are several reorderings in arrays in this patch, why?

Is this because when the settings are saved, that is the place the driver is? And so this is making the order in the comments match what might be saved?

--
2.
@catch's concern in #27 was addressed. good.
--
3.
in #36, @Damien Tournoud had concerns:

There are a couple of issues in there:

  • We should use drupal_var_export() instead of var_export() here (and in the other branch below) to match our coding standards (especially the spacing after array);
  • The variable needs to be cleared first ($databases = array();), before outputting the sub-keys;
  • The keys ($db_name and $db_roles) should be output using drupal_var_export() too, as in:
    $buffer .= '$databases[' . drupal_var_export($db_name) . '][' . drupal_var_export($db_role) . '] = ' . drupal_var_export($values, TRUE) . ';';
    

I think this is still needs work to address that.

yesct’s picture

#63 is a good point. but I think that would be a separate issue. I searched and didn't find an existing issue to use yml for settings. So someone could create that issue and link it back to here.

iantresman’s picture

@#65 YesCT

Done.

yesct’s picture

hosef’s picture

@#64
I rearranged the database settings example to match what Drupal actually output, because they were quite different from each other. I thought that would make it less confusing for a novice coder who needed to change the settings manually.

yesct’s picture

Issue summary: View changes
mistermarco’s picture

Issue summary: View changes
dandaman’s picture

I spent a while looking at this and I'm not sure what need to be changed anymore.

The majority of the code in #49 is not actually run at this time because the $prefix value when _drupal_rewrite_settings_dump_one() is run is $databases, not $databases = . Also, even if I change it to $databases, that code is not run because _drupal_rewrite_settings_dump_one() is only run on objects, I believe, and that is an array.

Without any patches, though, the database structure in 8.x core is what the documentation shows:

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

I'm not sure what the issue is, except for maybe a separate issue that this is written at the bottom of the settings.php file and not replacing $databases = array(); towards the top of the file. Also, I think the point of settings $databases = array(); right above this is a good idea if it is at the bottom because then you don't have things less clearly overwritten.

And finally, the API Docs for drupal_var_export() says that this function is deprecated and should be changed to Variable::export(). I think that means if we do use that that the statement use Drupal\Component\Utility\Variable; should be added to the top of the file to make sure the dependency of the Variable class is loaded.

mistermarco’s picture

Issue summary: View changes
mistermarco’s picture

Issue summary: View changes
mistermarco’s picture

Status: Needs work » Needs review
StatusFileSize
new1.59 KB
mistermarco’s picture

Issue summary: View changes
iantresman’s picture

I would still much prefer settings.php changed to settings.yml as yaml is much easier to read.

sun’s picture

Status: Needs review » Needs work
  1. 'driver' is legacy information, still actively used, duplicates 'namespace'.
  2. 'driver' + 'namespace' should always come first; they declare which database driver is used.
  3. The remaining options have a natural order, too: (3) host, (4) port, (5) database, (6) username, (7) password.
yesct’s picture

yesct’s picture

Issue tags: -Novice

I'm not sure that @sun's feedback is actionable here.
This is just about making the comment match what the setting get's saved as.

If the suggestion is to change the order of the saved things, I think that is a different issue.

--
but does need work to reroll/remake to apply to head since it does not apply anymore.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

joachim’s picture

Version: 8.5.x-dev » 8.6.x-dev
Status: Needs work » Needs review
StatusFileSize
new572 bytes

This has changed quite a bit since the earlier patches.

Here's an update based on the difference between default.settings.php and what's been written in my settings.php by the installer.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new192 bytes

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.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.