public static function selectSql($tablename, $fields, $where_clause=false) {
        $sql = "SELECT ";
        $first = true;
        foreach ( $fields as $field ) {
            if ( ! $first ) $sql .= ', ';
            $sql .= $field;
            $first = false;
        }
        $sql .= "\n FROM ".$tablename;
        if ( $where_clause && strlen($where_clause) > 0 ) $sql .= "\nWHERE ".$where_clause;
        return $sql;
    }