1 bootstrap.inc 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.

This function is deprecated in Backdrop and will be removed in a future release. Variables are not managed through the configuration system, so they cannot be moved between environments safely. If your module needs to save configuration settings, use config_set() instead. If you need to save an environment-specific setting (such as the last time cron ran), use state_set() instead.

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.

Deprecated

since 1.0

See also

variable_del()

variable_get()

config_set()

state_set()

File

core/includes/bootstrap.inc, line 1224
Functions that need to be loaded on every Backdrop request.

Code

function variable_set($name, $value) {
  global $conf;

  watchdog_deprecated_function('bootstrap', __FUNCTION__);

  db_merge('variable')->key(array('name' => $name))->fields(array('value' => serialize($value)))->execute();

  cache('bootstrap')->delete('variables');

  $conf[$name] = $value;
}