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.

  • OR can I add it using the "INSERT" tab in PHPMyAdmin?
    – MrSnrub
    Jun 24, 2021 at 20:37
  • 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. Jul 4, 2021 at 10:24
  • Can you give an example of how to do it through PHPMyAdmin?
    – MrSnrub
    Jul 5, 2021 at 11:34

3 Answers 3


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

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";}')
drush vset <variable-name> <variable-value>

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.