mySQLi 准备好的语句:Fetch() 失败

发布于 2024-12-04 19:18:09 字数 939 浏览 1 评论 0原文

我的查询始终无法获取。它在我的 SQL 控制台中运行得很好,所以我不知所措。这是代码。

$q_st = "SELECT tryouts.playerFName,tryouts.playerLName,tryouts.mainEmail,
tryouts.secondEmail, players.number FROM tryouts LEFT JOIN players ON
players.userID=tryouts.userID WHERE players.team = ? 
ORDER BY tryouts.playerLName";

$stmt = $GLOBALS['m']->prepare($q_st);
$stmt->bind_param("s",$GLOBALS['c_team']);
$stmt->execute();
$stmt->bind_result($pfn,$pln,$em,$em2,$num);

if($stmt->fetch()==false)
{
echo($GLOBALS['m']->error . $GLOBALS['m']->sqlstate ." Haha It doesn't work and YOU     don't know why!!!");
}
else
{
while($stmt->fetch())                  {
static $count3;
echo ($pfn . " " . $pln . " " . $num . "<input type=\"checkbox\" class=\"player\" value=\"" . $em ."\"  id=\"player ". ++$count3 . "\"><br />");
}              
}

结果是“00000 哈哈,它不起作用,你不知道为什么!!!”

我已经测试了所有其他 stmt 参数,它们都成功通过。 有什么想法吗?

My query keeps failing to fetch. It works just fine in my SQL Console so I'm at a loss. Here's the code.

$q_st = "SELECT tryouts.playerFName,tryouts.playerLName,tryouts.mainEmail,
tryouts.secondEmail, players.number FROM tryouts LEFT JOIN players ON
players.userID=tryouts.userID WHERE players.team = ? 
ORDER BY tryouts.playerLName";

$stmt = $GLOBALS['m']->prepare($q_st);
$stmt->bind_param("s",$GLOBALS['c_team']);
$stmt->execute();
$stmt->bind_result($pfn,$pln,$em,$em2,$num);

if($stmt->fetch()==false)
{
echo($GLOBALS['m']->error . $GLOBALS['m']->sqlstate ." Haha It doesn't work and YOU     don't know why!!!");
}
else
{
while($stmt->fetch())                  {
static $count3;
echo ($pfn . " " . $pln . " " . $num . "<input type=\"checkbox\" class=\"player\" value=\"" . $em ."\"  id=\"player ". ++$count3 . "\"><br />");
}              
}

Result is "00000 Haha It doesn't work and YOU don't know why!!!"

I've tested all the other stmt parameters and they all come through with success.
Any ideas?

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

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

发布评论

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

评论(1

走走停停 2024-12-11 19:18:09

由于 mysqli_stmt_fetch() 方法可以返回 null< /code> 和 false 你必须使用 === 来检查返回值是否为 false (或者是否为 null 或不)。否则,您会将返回值 null 解释为错误代码,但事实并非如此。

此外,您的代码通过第一次 fetch() 调用从结果中读取一行,但您不以任何方式处理返回的行。您正在删除结果集的第一行,这可能不是您想要的。

如果您想知道结果集有多少行,请使用 mysqli_stmt_num_rows< /a>.

As the mysqli_stmt_fetch() method can return null and false you have to use === to check if the returned value is false or not (or if it is null or not). Otherwise you interpret the return value null as an error code, which it isn't.

Additionally your code reads one row from the result with your first fetch() call, but you don't handle the returned row in any way. You are dropping the first row of your result set which might not be something you want.

If you want to know how many rows the result set has use mysqli_stmt_num_rows.

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