Comparing two functions. Need review...

From: Dimension7 (dimension_at_seven.com)
Date: 04/30/04


Date: Thu, 29 Apr 2004 20:09:41 -0800

All,
I am comparing to functions to see which is "better". In better, I mean more
efficient, optimize, faster, etc.
I have read other posts from other boards, but I'm not really sure of the
benefits or if there is a speed increase
with one vs. the other.

FIRST VERSION
function is_active($module) {
    global $prefix, $dbi;
    $result = sql_query("select active from web_modules where
title='$module'", $dbi);
    list ($act) = sql_fetch_row($result, $dbi);
    if (!$result OR $act == 0) {
 return 0;
    } else {
 return 1;
   }
}

SECOND VERSION
function is_active($module) {
    global $dbi;
    static $save;
    if (is_array($save)) {
        if (isset($save[$module])) return ($save[$module]);
        return 0;
    }
    $result = sql_query("select active from web_modules where
title='$module'", $dbi);
    while ($act = sql_fetch_row($result, $dbi)) {
        $save[$act[0]] = 1;
    }
    if (isset($save[$module])) return ($save[$module]);
    return 0;
}