function variable_set

7.x variable_set($name, $value)
6.x variable_set($name, $value)

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.


$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



358 calls to variable_set()
AccessDeniedTestCase::testAccessDenied in drupal-7.x/modules/system/system.test
ActionLoopTestCase::testActionLoop in drupal-7.x/modules/simpletest/tests/actions.test
Set up a loop with 3 - 12 recursions, and see if it aborts properly.
AggregatorRenderingTestCase::testFeedPage in drupal-7.x/modules/aggregator/aggregator.test
Creates a feed and checks that feed's page.
aggregator_update_7001 in drupal-7.x/modules/aggregator/aggregator.install
Add aggregator teaser length to settings from old global default teaser length
AJAXFrameworkTestCase::testLazyLoadOverriddenCSS in drupal-7.x/modules/simpletest/tests/ajax.test
Tests that overridden CSS files are not added during lazy load.

... See full list


drupal-7.x/includes/, line 973
Functions that need to be loaded on every Drupal request.


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;