6

I was reading default.settings.php for Drupal 7.x this afternoon, and came across this comment:

/*
 * 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.
 */

This is different in Drupal 8:

/*
 * Transaction support is enabled by default for all drivers that support it,
 * including MySQL. To explicitly disable it, set the 'transactions' key to
 * FALSE.
 * Note that some configurations of MySQL, such as the MyISAM engine, don't
 * support it and will proceed silently even if enabled. If you experience
 * transaction related crashes with such configuration, set the 'transactions'
 * key to FALSE.
 */

So, how does db_transaction() work then on MySQL in Drupal 7?

Is this comment outdated, or should I explicitly set

$databases['default']['default']['transactions'] = TRUE;

if I know everything is InnoDB (which is the default for Drupal 7.

2
  • 1
    I don't know the answer to this 100% but I think transactions happen even if this value is not set. Example: db_transaction() is used in things like node_save()
    – mikeytown2
    Commented Feb 27, 2014 at 1:49
  • @mikeytown2 That is why I am really confused here. I only noticed this because I was adding the READ COMMITTED setting to a site, and happened to read the comments in settings.php.
    – mpdonadio
    Commented Feb 27, 2014 at 3:19

1 Answer 1

1

The constructor for the DatabaseConnection_mysql class, has this code and comment:

public function __construct(array $connection_options = array()) {
  // This driver defaults to transaction support, except if explicitly passed FALSE.
  $this->transactionSupport = !isset($connection_options['transactions']) ||
    ($connection_options['transactions'] !== FALSE);

In addition, there is support and workaround for the MySQL implementation of transactions (including no proper support for DDL transactions).

This suggests that the documentation in the settings file is incorrect.

4
  • I would love someone more familiar with the database later to confirm or deny this. I am not seeing when/where this statement got into the file.
    – mpdonadio
    Commented Feb 27, 2014 at 13:44
  • 1
    Confirmed, the documentation was part of the initial commit of DBTNG, and later on the default was switched but the documentation wasn't updated. The reason this was changed is that MySQL initially did not use InnoDB, so it was not possible to default to TRUE.
    – Berdir
    Commented Mar 5, 2014 at 8:05
  • 1
    See drupal.org/node/616650, the 8.x version was updated in drupal.org/node/1221772, but the issue was closed instead of set to backport to 7.x, as Dries forgot to do that often.
    – Berdir
    Commented Mar 5, 2014 at 8:07
  • Thanks @Berdir. Those issues, nor the referenced question there, didn't turn up when I searched.
    – mpdonadio
    Commented Mar 5, 2014 at 12:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.