Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.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
在PHP5中将准备好的查询结果绑定到数组中_Php_Arrays - Fatal编程技术网

在PHP5中将准备好的查询结果绑定到数组中

在PHP5中将准备好的查询结果绑定到数组中,php,arrays,Php,Arrays,我试图将$stmt->fetch生成的结果绑定到一个数组中。一个糟糕的解决方案是我把它放在while循环中,然后从那个里得到数组中的结果。我问这个问题的唯一原因是我不能在PHP5.3中使用mysqli_result::fetch_数组或mysqli_result::fetch_assoc.,get_result作为它的结果,我的服务器不支持它。请让我知道有没有更好的方法来使用像get_result这样的短代码 我试过了,但到目前为止运气不好 $stmt->execute();

我试图将$stmt->fetch生成的结果绑定到一个数组中。一个糟糕的解决方案是我把它放在while循环中,然后从那个里得到数组中的结果。我问这个问题的唯一原因是我不能在PHP5.3中使用mysqli_result::fetch_数组或mysqli_result::fetch_assoc.,get_result作为它的结果,我的服务器不支持它。请让我知道有没有更好的方法来使用像get_result这样的短代码

我试过了,但到目前为止运气不好

$stmt->execute();     

/* Bind results */
$stmt -> bind_result($abc);

/* Fetch the value */
$row = $stmt -> fetch();
$row1=$row;

我之所以使用此替代代码,是因为我也不能使用get_result,我在这里找到了它:

<?php
$stmt = $db->prepare( ' YOUR SQL QUERY ' ) ); /* edit to your needs */
$stmt->bind_param( ... ); /* edit to your needs */

$stmt->execute();

$meta = $stmt->result_metadata();
$fields = $result = array();
while ($field = $meta->fetch_field()) { 
    $var = $field->name; 
    $$var = null; 
    $fields[$var] = &$$var; 
}
call_user_func_array(array($stmt,'bind_result'),$fields);
$i = 0;
while ($stmt->fetch()) {
    $result[$i] = array();
    foreach($fields as $k => $v)
        $result[$i][$k] = $v;
    $i++;
}
?>