$object = array();
while($row = mysql_fetch_object($result))
{
$object[] = $row;
}
$object = new stdClass($object);
或
class myClass{
private $counter = 0;
public function add($row){
$count = $counter++;
$this->$count = $row;
}
}
$object = new myClass();
while($row = mysql_fetch_object($result))
{
$object->add($row);
}
或
class myClass implements ArrayAccess{
private $counter = 0;
public function offsetSet($offset, $value) {
if (is_null($offset)) {
$count = $counter++;
$this->$count = $value;
} else {
$this->$offset = $value;
}
}
public function offsetExists($offset) {
return isset($this->$offset);
}
public function offsetUnset($offset) {
unset($this->$offset);
}
public function offsetGet($offset) {
return isset($this->$offset) ? $this->$offset : null;
}
}
$object = new myClass();
while($row = mysql_fetch_object($result))
{
$object[] = $row;
}
这并不真正使一个很大的意义。你想让结果对象看起来像什么? – deceze 2011-12-19 07:36:15
你能否澄清预期结果需要做些什么?你想要迭代对象吗? – SeanNieuwoudt 2011-12-19 07:41:59
你想访问这样的行吗? $ object-> 0-> COLUMN 这是不可能的。实际上它没有任何意义。 – 2011-12-19 07:57:14