Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
检索PHP准备的语句字段数据_Php_Mysqli - Fatal编程技术网

检索PHP准备的语句字段数据

检索PHP准备的语句字段数据,php,mysqli,Php,Mysqli,我正在使用Mysqli扩展和一个PHP编写的语句SELECT我不知道我在选择中有多少字段,直到我完成了 $stmt->execute(); $fieldcnt = $stmt->field_count; 因为这个,我在做一个 $stmt->bind_result(list of parms); 也就是说,因为我不知道返回了多少字段,所以我不知道如何构建“parm列表” 因此,我需要一些关于如何访问返回字段的建议 不要使用bind_result,而要使用 这将为每行返回一个关

我正在使用Mysqli扩展和一个PHP编写的语句
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);