检索PHP准备的语句字段数据
我正在使用Mysqli扩展和一个PHP编写的语句检索PHP准备的语句字段数据,php,mysqli,Php,Mysqli,我正在使用Mysqli扩展和一个PHP编写的语句SELECT我不知道我在选择中有多少字段,直到我完成了 $stmt->execute(); $fieldcnt = $stmt->field_count; 因为这个,我在做一个 $stmt->bind_result(list of parms); 也就是说,因为我不知道返回了多少字段,所以我不知道如何构建“parm列表” 因此,我需要一些关于如何访问返回字段的建议 不要使用bind_result,而要使用 这将为每行返回一个关
SELECT代码>我不知道我在选择中有多少字段,直到我完成了
$stmt->execute();
$fieldcnt = $stmt->field_count;
因为这个,我在做一个
$stmt->bind_result(list of parms);
也就是说,因为我不知道返回了多少字段,所以我不知道如何构建“parm列表”
因此,我需要一些关于如何访问返回字段的建议 不要使用bind_result,而要使用
这将为每行返回一个关联数组:
while ($row = $stmt->fech_assoc()) {
print_r($row);
}
如果您必须使用bind\u result()
,您可以利用call\u user\u func\u array()来完成此任务
// create an array the size of the number of parameters
$params = array_fill(0, $fieldcnt, null);
// call bind_result, resulting in every column of the result to be
// bound to a value in $params
call_user_func_array(array($stmt, 'bind_result'), $params);
// take a look at all the params
print_r($params);