note 83251 added to function.mysql-fetch-object

From: Date: Fri, 16 May 2008 19:24:56 +0000
Subject: note 83251 added to function.mysql-fetch-object
Groups: php.notes 
Request: Send a blank email to php-notes+get-139455@lists.php.net to get a copy of this message
This is another way to load variables quickly within $this, and allows for intervention on variable names. All columns from the single-row result are loaded and accessed via $this->_variableName. <? class MyClass{ public function _load($nID) { $Q = "SELECT * FROM myTable"; if($aTmp = RETURN_Q_ARRAY($Q)) { $aTmp = $aTmp[0]; $aK =array_keys($aTmp); foreach($aK as $sK) { if(!is_numeric($sK)) $this->{"_$sK"}=$aTmp[$sK]; } return true; } return false; } } $o = new MyClass; $o->_load(1); echo $o->_id; //1 echo $o->_otherColumn; //otherColumn value ---- Server IP: 64.71.164.2 Probable Submitter: 134.29.238.70 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-fetch-object.php Edit -- https://master.php.net/note/edit/83251 Del: integrated -- https://master.php.net/note/delete/83251/integrated Del: useless -- https://master.php.net/note/delete/83251/useless Del: bad code -- https://master.php.net/note/delete/83251/bad+code Del: spam -- https://master.php.net/note/delete/83251/spam Del: non-english -- https://master.php.net/note/delete/83251/non-english Del: in docs -- https://master.php.net/note/delete/83251/in+docs Del: other reasons-- https://master.php.net/note/delete/83251 Reject -- https://master.php.net/note/reject/83251 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#139455) next »