如何将选定数据提取到对象并使用PDO检索所选列名? 现在,我正在循环中获取一个Member对象,并通过从“fetch数组”访问它来手动将每列添加到该对象。有没有办法自动获取已被选择的列名?
$sql = "SELECT member.name, member.email FROM member WHERE id = :id";
$param = array(':id' => $id);
$stmt = $this->m_db->select($sql, $param);
$ret = new MemberArray();
while ($f = $stmt->fetch()) {
$member = new Member($f['name'], $f['email']);
$ret->add($member);
}
return $ret;