使用 php + MySQLi 获取数据时可以使用 while 吗?
Is it okay to use while when fetching data using php + MySQLi?
用php + MySQLi 取数据的时候用while可以吗?它可以作为任何明显问题的先决条件吗?
$getpost->bind_result($returned_post);
while($getpost->fetch()){
echo($returned_post);
}
调用mysqli_stmt_fetch()取数据时正常,MySQLclient/server协议将绑定列的数据放入指定变量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();
?>
您可以阅读更多内容:
用php + MySQLi 取数据的时候用while可以吗?它可以作为任何明显问题的先决条件吗?
$getpost->bind_result($returned_post);
while($getpost->fetch()){
echo($returned_post);
}
调用mysqli_stmt_fetch()取数据时正常,MySQLclient/server协议将绑定列的数据放入指定变量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();
?>
您可以阅读更多内容: