3

I happen to read through the commented lines in settings.php under the "Database settings" (around line no. 45) the following text:

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.

My databases array, auto-generated by Drupal Installer, is the following one:

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

Is it true that my site is not transaction aware until I add a key/value, 'transaction' => TRUE (preferably after 'prefix' => '') to $databases?

2 Answers 2

2

Looking at DatabaseConnection_pgsql::__construct(), I noticed the following code:

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

The code sets DatabaseConnection_pgsql::$transactionSupport to TRUE when the connection parameters don't contain the array index "transactions," which is one you should set in your settings.php file (it's not "transaction"), or when that array index is used in the connection parameters and it is not set to FALSE.

The same code is contained in DatabaseConnection_mysql::__construct(); in this case, the connection parameters (the ones set in the settings.php file) should be set not to use transactions only when the tables used are MyISAM.

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

Also DatabaseConnection_sqlite::__construct() contains the same code.

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

In short, the drivers used by Drupal always set the transaction support to TRUE, and users should set it to FALSE when they are using MyISAM tables, or they don't want to enable the transaction support.

2
  • Thanks @kiamlaluno and @wiifm, I guess the line In order to enable transaction support for a given database, set the 'transactions' key to TRUE to be removed/rephrased.
    – Sivaji
    Commented Jul 17, 2011 at 18:57
  • 1
    Created an issue in drupal.org to fix it drupal.org/node/1221772#comment-4746926
    – Sivaji
    Commented Jul 18, 2011 at 6:39
0

First things first, your database requires the InnoDB engine as MyISAM tables do not support transactions.

From the sounds of the README you then need to add the key to the array as you suggested above.

More information on transactions in general http://drupal.org/node/355875

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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