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