PEAR Forum :: PHP Extension and Application Repository

PEAR Forum Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Constructor MDB_QueryTool_Result_Row ignores keys

 
Post new topic   Reply to topic    PEAR Forum Forum Index -> Database
View previous topic :: View next topic  
Author Message
gegtot



Joined: 26 Nov 2007
Posts: 1

PostPosted: Mon Nov 26, 2007 11:35 pm    Post subject: Constructor MDB_QueryTool_Result_Row ignores keys Reply with quote

Hi all,

I use the class Bikes as a returnclass of BikesQT. In FetchBike($bikeno) I join the table, bike_types, and try to access its values using this returnclass.

My problem is that I cannot access the values of bike_types and I just found out why. When the query is built an initial '_' is added to every column name of the bike_types. When the contructor MDB_QueryTool_Result_Row returns the result, it skips every key beginning with '_'.

the query looks like this: SELECT bike_types.`id` AS `_bike_types_id`,bike_types.`type` AS `_bike_types_type`,bike_types.`pricetype` AS `_bike_types_pricetype`,bike_types.`bundle_size` AS `_bike_types_bundle_size`,bike_types.`time` AS `_bike_types_time`,bikes.`bike_id` AS `bike_id`,bikes.`lock_code` AS `lock_code`,bikes.`code_status` AS `code_status`,bikes.`status` AS `status`,bikes.`phone_number` AS `phone_number`,bikes.`type` AS `type`,bikes.`start_time` AS `start_time`,bikes.`end_time` AS `end_time`,bikes.`history_id` AS `history_id` FROM bikes,bike_types WHERE bikes.type = bike_types.type AND bikes.bike_id='test'

Is there a way of getting around this?

Best regards,
Georg

Code:

Class BikesQT extends MDB_QueryTool
{
    public $table        = 'bikes';
    public $primaryCol =   'bike_id';
   // protected $BikeFirstAttempt;
    public $_bike_types_pricetype;
       
   public $tableSpec = array(
        array('name'  => 'bikes', 'shortName' =>  'bikes'),
        array('name'  => 'bike_types', 'shortName' =>  'bike_types'),
    );
   
   function FetchBike($BikeNumber)
   {
       $this->addJoin('bike_types', 'bikes.type = bike_types.type');
       $this->setSelect('bikes.bike_id', 'bike_types.price_type');
       $BikeObj = $this->get($BikeNumber);
      if ($BikeObj != null)
      {
         $SelectedBike = $BikeObj->fetchRow();
         if($SelectedBike)
         {
            $SelectedBike->SetRented();
            $SelectedBike->save();
         }
         return $SelectedBike;
      }
      else
      {
         return false;
      }

   }

}

Class Bikes extends MDB_QueryTool_Result_Row
{   
    public $bike_id;
public $status;
    public $price_type;
    public $bundle_size;
}



 function MDB_QueryTool_Result_Row($arr, &$qt)
    {
        foreach ($arr as $key => $value) {
            //Ignore keys beginning with '_'
            if (substr($key,0,1) != '_') {
                $this->$key        = $value;
                $this->_keyarray[] = $key;
            }
        }
        $this->_qt_instance = $qt;
    }
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    PEAR Forum Forum Index -> Database All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



PEAR Forum topic RSS feed 
Powered by phpBB © 2001, 2005 phpBB Group

Provided by Ministry of Web developement

'Actiemonitor' online projectmanagement software