It's there a chance to retrieve all key/value, stored in variable table, that have a prefix, using variable_get()? e.g: variable_get("prefix_*")

Or I have to use db_select('variable')?


I'm afraid not, variable_get() is a very simple function that just returns an item in the global $conf array, there's no method for searching built in.

You could write your own variable_select() function though, and you wouldn't have to go into the database as the entire variable table is loaded into $conf at the start of the page build. It might go something like this:

function variable_select($prefix) {
  $found = array();

  global $conf;
  foreach ($conf as $key => $value) {
    if (strpos($key, $prefix) === 0) {
      $found[$key] = $value;

  return empty($found) ? FALSE : $found;

I'm sure that could be improved but it's a start. It's worth noting that this method might match elements from the settings.php file that aren't actually variables in the database as such.

For example, if your prefix is data, it's likely you'll see the $conf['databases'] variable from settings.php in your results. There wouldn't be a way around that without going directly into the db I don't think.

  • nice! This is great! – vtemian Aug 29 '12 at 9:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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