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

53 calls to variable_set()
cache_clear_all in includes/cache.inc
Expire data from the cache. If called without arguments, expirable entries will be cleared from the cache_page and cache_block tables.
cache_get in includes/cache.inc
Return data from the persistent cache. Data may be stored as either plain text or as serialized data. cache_get will automatically return unserialized objects and arrays.
color_scheme_form_submit in modules/color/color.module
Submit handler for color change form.
comment_update_1 in modules/comment/comment.install
Changed node_comment_statistics to use node->changed to avoid future timestamps.
comment_update_6002 in modules/comment/comment.install
Changed comment settings from global to per-node -- copy global settings to all node types.

... See full list

File

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

Code

function variable_set($name, $value) {
  global $conf;
  $serialized_value = serialize($value);
  db_query("UPDATE {variable} SET value = '%s' WHERE name = '%s'", $serialized_value, $name);
  if (!db_affected_rows()) {
    @db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", $name, $serialized_value);
  }
  cache_clear_all('variables', 'cache');
  $conf[$name] = $value;
}