note 92784 modified in mysqli-result.fetch-object by felipe
| From: | felipe@php.net | Date: | Sun, 09 Aug 2009 15:19:43 +0000 |
| Subject: | note 92784 modified in mysqli-result.fetch-object by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-159234@lists.php.net to get a copy of this message | ||
I don't know why no one talk about this.
fetch_object is very powerful since you can instantiate an Object which has the methods you wanna
have.
You can try like this..
<?php
class PowerfulVO extends AbstractWhatEver {
public $field1;
private $field2; // note : private is ok
public function method(){
// method in this class
}
}
$sql = "SELECT * FROM table ..."
$mysqli = new mysqli(........);
$result = $mysqli->query($sql);
$vo = $result->fetch_object('PowerfulVO');
?>
Note : if the field is not defined in the class, fetch_object will add this field for you as public.
The method is very powerful, especially if you want to use a VO design pattern or class mapping
feature with Flex Remoting Object( Of course, you need to have ZendAMF or AMFPHP ..framework)
Hope this help and open new possibilities for you
--was--
I don't know why no one talk about this.
fetch_object is very powerful since you can instantiate an Object which has the methods you wanna
have.
You can try like this..
class PowerfulVO extends AbstractWhatEver {
public $field1;
private $field2; // note : private is ok
public function method(){
// method in this class
}
}
$sql = "SELECT * FROM table ..."
$mysqli = new mysqli(........);
$result = $mysqli->query($sql);
$vo = $result->fetch_object('PowerfulVO');
Note : if the field is not defined in the class, fetch_object will add this field for you as public.
The method is very powerful, especially if you want to use a VO design pattern or class mapping
feature with Flex Remoting Object( Of course, you need to have ZendAMF or AMFPHP ..framework)
Hope this help and open new possibilities for you
http://php.net/manual/en/mysqli-result.fetch-object.php