如何将选定的数据提取到对象并使用 PDO 检索选定的列名称?现在,我正在循环中获取成员对象,并通过从“获取数组”访问它来手动将每一列添加到对象中。有没有办法自动获取已选择的列名?
$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;