Score:0

Is there a way to add a variable to the variable table through the Admin menu

in flag

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.

MrSnrub avatar
in flag
OR can I add it using the "INSERT" tab in PHPMyAdmin?
in flag
You _could_ use PHPMyAdmin, to add the key/value pair, but you're better adding it to the `$conf[]` array in the `settings.php` file 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.
MrSnrub avatar
in flag
Can you give an example of how to do it through PHPMyAdmin?
Score:2
in flag

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 value column is the string bar, it will give you s:3:"bar";
  • if the value column is the array ['bar','baz'] it will give you
    a: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";}')
Score:1
fr flag
drush vset <variable-name> <variable-value>
Score:1
us flag

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';
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.