Can I set a new key/value pair for the variable table from the Administrator admin/config menu in a Drupal 7 site? I don't want to have to create a one-time custom module that only contains a variable_set() function.
3 Answers
I don't know about your PHPMyAdmin installation, but mine won't allow me to insert the data into the value column in the variable table, as it's a blob column. The data in that column is serialized as you can see in the implementation. As a result, adding it via the "Insert" tab is problematic. Instead, I'll explain how you can add it in the "SQL" tab.
If you use an online serializer site, you can generate the proper data for the variable named foo
- if the
valuecolumn is the stringbar, it will give yous:3:"bar"; - if the
valuecolumn is the array['bar','baz']it will give youa:2:{i:0;s:3:"bar";i:1;s:3:"baz";}
Then, use the "SQL" tab (instead of the "Insert" tab) and craft the appropriate insert statement.
If the value is a string:
INSERT INTO `variable`(`name`, `value`) VALUES ('foo','s:3:"bar";') If the value is an array:
INSERT INTO `variable`(`name`, `value`) VALUES ('foo','a:2:{i:0;s:3:"bar";i:1;s:3:"baz";}') You can override a persistent variable in the settings.php file. default.settings.php file contains example code for achieving that.
// Change the site name to 'My Drupal site'. $conf['site_name'] = 'My Drupal site';
$conf[]array in thesettings.phpfile if you want to make it persistent, as suggested by @apaderno, or if you've got access to the command line and Drush, use @anonymous' solution. Both will help (but not guarantee) that the variable is cast correctly.