I am writing some custom code that requires communication with the db. In my functions I use: global $db; but I keep getting 'scolded' on programming forums for using globals.

Is there a better way for me to use the db in code such as the following when communicatin with the zencart db?:

Code:
function beginProcess(){
    global $db; 
    $sql = "SELECT last_batch from ".TABLE_STATUS.";";            
    $lastBatch = $db->Execute($sql);
    $lastBatch=(int)$lastBatch->fields['last_batch'];
    echo "<BR/>Last Batch = ".$lastBatch;

    if ($lastBatch >=1 && $lastBatch <=3 ){
        $batch = $lastBatch +1;
    }else{
        $batch = 1;
    }
        processBatch($batch);
}