使用准备好的语句返回特定行

发布于 2024-08-11 15:25:03 字数 601 浏览 3 评论 0原文

我有一个问题,我准备好的语句似乎只返回返回的行数而不是行的值。下面是我的代码。我确实尝试过谷歌,但它没有告诉我任何东西!如果有人能告诉我我做错了什么以及如何解决它,我将非常感激。谢谢

$query2 = 'SELECT * FROM kids_entry WHERE email = ?';
$stmt2 = $connection->prepare($query2);

// bind the user id as an integer to the first ?
$stmt2->bind_param('s', $email);
$stmt2->execute(); // execute the statement

$stmt2->store_result(); // this call is required for the next operation 

while($row1 = $stmt2->fetch()){
    printf ("%s \n", $entries);
}

编辑

我只是尝试用 while 循环替换 if ,我得到了同样的结果。

编辑2

添加新代码后,它可以工作,但是我如何将其分配给$变量?

I have a problem where my prepared statement appears to only be returning the number of rows returned rather than the value of the row. Below is my code. I did try google for this but it doesn't tell me anything! If someone could tell me what I am doing wrong and how to fix it I would be very appreciative. Thanks

$query2 = 'SELECT * FROM kids_entry WHERE email = ?';
$stmt2 = $connection->prepare($query2);

// bind the user id as an integer to the first ?
$stmt2->bind_param('s', $email);
$stmt2->execute(); // execute the statement

$stmt2->store_result(); // this call is required for the next operation 

while($row1 = $stmt2->fetch()){
    printf ("%s \n", $entries);
}

EDIT

I did just try replacing the if with a while loop and i got the same thing.

EDIT 2

Having added the new code it works but how would i assign this to a $variable?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一梦等七年七年为一梦 2024-08-18 15:25:03

请参阅 php 文档中的示例:
mysqli_stmt_fetch

/* execute statement */
$stmt->execute();

/* bind result variables */
$stmt->bind_result($name, $code);

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

/* close statement */
$stmt->close();

See the example in the php documentation:
mysqli_stmt_fetch

/* execute statement */
$stmt->execute();

/* bind result variables */
$stmt->bind_result($name, $code);

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

/* close statement */
$stmt->close();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文