调用mysqli_stmt_store_result后如何获取fetch_ *行?

时间:2014-01-22 19:57:26

标签: php mysqli

<?php

$stmt = $mysqli->prepare("SELECT * FROM test WHERE dataStr = ? LIMIT 20");
$stmt->bind_param("s", $search);
$stmt->execute();

$stmt->store_result();
echo "rows are " . $stmt->num_rows;

$rs = $stmt->get_result();
while($r = $rs->fetch_object()) print_r($r);

?>

当我致电$stmt->store_result()$stmt->num_rows工作时,$stmt->get_result()的后续调用将返回FALSE。如果我评论store_result()行,一切正常(当然除了num_rows)

在调用mysqli_result后,如何访问fetch_array()类实例及其fetch_assoc()fetch_object()$stmt->store_result()方法?

1 个答案:

答案 0 :(得分:1)

试试这个,

<?php

        $stmt = $mysqli->prepare("SELECT * FROM test WHERE dataStr = ? LIMIT 20");
        $stmt->bind_param("s", $search);
        $stmt->execute();

        $stmt->store_result();
        echo "rows are " . $stmt->num_rows;

        $result = $stmt->get_result();

        while ($row = $result->fetch_assoc()) 
        {

            echo 'ID: '.$row['id'].'<br>';

        }

        $stmt->free_result();


    ?>