Jump to content

more classes


l0ve2hat3

Recommended Posts

how do i access mssql_value in db_manager class, if i am in pca_inventory class???

 

 

<?php

class db_manager{

    public $dbname="gnglatt";
    public $host="MARS\PCAMERICA";
    public $port="1092";
    public $user="demo";
    public $password="demo";
    public $connection;

   function _connect(){
        $this->connection=mssql_connect($this->host,$this->user,$this->password);
        mssql_select_db($this->dbname,$this->connection);
   }

   public function check_connect(){
        if(!$this->connection)$this->_connect();
   }
   public function query($query){
            $this->check_connect();
           $qresult=mssql_query($query) or Die($query);
           return $qresult;
   }


  public function mssql_value($table,$field,$id,$idfield="id"){
  	$sql='SELECT ['.$field.'] FROM ['.$table.'] WHERE ['.$idfield.']="'.$id.'"';
  	$value=mssql_result($this->query($sql),0,$field);
  	return $value;
  }
}





class pca_inventory{
    public function get_price($item_number){
        return db_manager::mssql_value('Inventory','Price',$item_number,'ItemNum');
    }

}


$item = new pca_inventory;
echo $item->get_price('LUNCHSPEC');


?>

Link to comment
Share on other sites

your concept of classes is still off. i've sat her trying to type out an explanation, but can't seem to come up with something. there is something about classes where it is so hard to explain to someone else. did you go through that tutorial I posted in your other thread?

Link to comment
Share on other sites

yeah i went through the tutorial...

 

i know i could use extends but i thought u might be able to do this..

 

class pca_inventory{
    public $db=new db_manager;
    public function get_price($item_number){
        return $db->mssql_value('Inventory','Price',$item_number,'ItemNum');
    }

}

 

no go...

 

rhodesa- any way to try to tell me what i am doing wrong with the concept??

 

 

Link to comment
Share on other sites

well this works, but y cant i make $db public?? so confused

 

class pca_inventory{

    public function get_price($item_number){
        $db=new db_manager;
        return $db->mssql_value('Inventory','Price',$item_number,'ItemNum');
    }

}

 

Why would you want it to be public?  In the vast, vast majority of cases, class properties should be private.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.