使用php + MySQLi获取数据时可以使用吗?

时间:2015-02-23 00:46:22

标签: php mysql database mysqli while-loop

使用php + MySQLi获取数据时可以使用吗?这可能是任何明显问题的先决条件吗?

$getpost->bind_result($returned_post);
while($getpost->fetch()){

    echo($returned_post);

}

1 个答案:

答案 0 :(得分:1)

当调用mysqli_stmt_fetch()来获取数据时,

是正常的,MySQL客户端/服务器协议将绑定列的数据放入指定的变量var1,....

见这个例子:

<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

/* prepare statement */
if ($stmt = $mysqli->prepare("SELECT Code, Name FROM Country ORDER BY Name LIMIT 5")) {
    $stmt->execute();

    /* bind variables to prepared statement */
    $stmt->bind_result($col1, $col2);

    /* fetch values */
    while ($stmt->fetch()) {
        printf("%s %s\n", $col1, $col2);
    }

    /* close statement */
    $stmt->close();
}
/* close connection */
$mysqli->close();

?>

您可以阅读更多内容:

  

http://php.net/manual/en/mysqli-stmt.bind-result.php