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()

121 calls to variable_set()
BlockHiddenRegionTest::testBlockNotInHiddenRegion in drupal/core/modules/block/lib/Drupal/block/Tests/BlockHiddenRegionTest.php
Tests that hidden regions do not inherit blocks when a theme is enabled.
BreadcrumbTest::testBreadCrumbs in drupal/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php
Tests breadcrumbs on node and administrative paths.
ColorTest::testValidColor in drupal/core/modules/color/lib/Drupal/color/Tests/ColorTest.php
Tests whether the provided color is valid.
ColorTest::_testColor in drupal/core/modules/color/lib/Drupal/color/Tests/ColorTest.php
Tests the Color module functionality using the given theme.
color_scheme_form_submit in drupal/core/modules/color/color.module
Form submission handler for color_scheme_form().

... See full list

File

drupal/core/includes/bootstrap.inc, line 1036
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('bootstrap')
    ->delete('variables');
  $conf[$name] = $value;
}