I am trying to make the transition from procedural to OO PHP and could use your help. Today I started looking at building a class to connect to any type of database.

I am sure that I am going wrong in multiple places but my current problem is that after I call set_server and $this->type is set, I follow up by calling query but query isn't picking up the $this->type variable. Where am I going wrong?

PHP Code:
<? if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Connection {
    
    function set_server($type, $username, $password, $hostname, $port)
    {
        if($type == "mysql")
        {
            $this->link = mysql_connect($hostname, $username, $password);
        }
        
    }

    function query($query_string)
    {
        if (!empty($query_string))
        {
            if($this->type == "mysql")
            {
                $this->query_string = $query_string;
                $this->result = mysql_query($query_string,$this->link);
                return $this->result;
            }
        }
        else
        {
            return false;
        }

    }
    
    function fetch($result="")
    {
         if(empty($result))
         { 
             $result = $this->result; 
             return $result;
         }
         else
         {
             if($this->type == "mysql")
             {
                return mysql_fetch_row($result);
             }
         }
         
        

    }
    
}

?>