我有以下 PHP 类:
class Dog
{
var $name;
var $age;
var $gender;
}
我有以下 sql 语句:
$sql = 'Select NAME,VALUE from dog_Details where id = 1';
$results = $this->db->query($sql);
$dog = new Dog();
foreach($results as $result)
{
$dog->$result->NAME = $result->VALUE; //This fails
}
PHP错误:
类 stdClass 的对象无法转换为字符串
问题:如何从结果集中动态绑定值?