You are here

function variable_set in Drupal 7

Same name and namespace in other branches
  1. 4 includes/bootstrap.inc \variable_set()
  2. 5 includes/bootstrap.inc \variable_set()
  3. 6 includes/bootstrap.inc \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()

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

... See full list

File

includes/bootstrap.inc, line 1257
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;
}