function variable_set

Sets a persistent variable.

Case-sensitivity of the variable_* functions depends on the database collation used. To avoid problems, always use lower case for persistent variable names.

Parameters

$name: The name of the variable to set.

$value: The value to set. This can be any PHP data type; these functions take care of serialization as necessary.

See also

variable_del()

variable_get()

387 calls to variable_set()
AccessDeniedTestCase::testAccessDenied in drupal/modules/system/system.test
ActionLoopTestCase::testActionLoop in drupal/modules/simpletest/tests/actions.test
Set up a loop with 3 - 12 recursions, and see if it aborts properly.
AggregatorRenderingTestCase::testFeedPage in drupal/modules/aggregator/aggregator.test
Creates a feed and checks that feed's page.
aggregator_update_7001 in drupal/modules/aggregator/aggregator.install
Add aggregator teaser length to settings from old global default teaser length
AJAXFormPageCacheTestCase::setUp in drupal/modules/simpletest/tests/ajax.test
Sets up a Drupal site for running functional and integration tests.

... See full list

File

drupal/includes/bootstrap.inc, line 1242
Functions that need to be loaded on every Drupal request.

Code

function variable_set($name, $value) {
  global $conf;
  db_merge('variable')
    ->key(array(
    'name' => $name,
  ))
    ->fields(array(
    'value' => serialize($value),
  ))
    ->execute();
  cache_clear_all('variables', 'cache_bootstrap');
  $conf[$name] = $value;
}