I need a function to return an array as an associate or object, with one input. Here's the code.

function fetch_article($key) {
    global $sysconfig;
    if ($sysconfig['datastore'] == 'wincache') {
          $data = wincache_ucache_get($key);
          return $data;
    }elseif ($sysconfig['datastore'] == 'apc'){
          $data = apc_fetch($key);
          return $data;
    }elseif ($sysconfig['datastore'] == ''){
          $data = $db->query("SELECT * FROM pages_content WHERE id = '" . $key . "'");
              $data = $data->fetch_assoc();
              return $data;
    }
}

I don't have that much experience working with functions, so please do bear with me.

share|improve this question
What's the problem? Put one more "}"at the end, and this code should work well. – Scorpil Nov 28 '10 at 19:33
@Scorpil, provide an answer and you might get it accepted. – Toby Allen Nov 28 '10 at 19:34
Sorry about that, in the third case, where the result set is an array, so $data['name'] might be produced, doesn't come out. In 500s the script. – Shamil Nov 28 '10 at 19:35
It seems that I was focussing on the wrong thing. $db was not globalised. – Shamil Nov 28 '10 at 19:50
feedback

1 Answer

up vote 0 down vote accepted

It's no problem to just return the variable holding the array object.

share|improve this answer
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

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