本文介绍了确定是否从准备好的陈述中不返回任何行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在对已经运行的mysqli查询执行预备语句.我在if(mysqli_num_rows($result) == 0)行时遇到了麻烦,因为它现在是字符串而不是mysqli_result.

I'm implementing prepared statements on my already working mysqli queries. I'm having trouble with a line if(mysqli_num_rows($result) == 0) as it's now a string instead of a mysqli_result.

if($nameAvailableStmt = mysqli_prepare($link, 'SELECT name FROM usetbl1 WHERE name=? LIMIT 1'))
{
    mysqli_stmt_bind_param($nameAvailableStmt, "s", $_POST['dangerous']);
    mysqli_stmt_execute($nameAvailableStmt);
    mysqli_stmt_bind_result($nameAvailableStmt, $result);
    mysqli_stmt_fetch($nameAvailableStmt);
}
if(mysqli_num_rows($result) == 0)

推荐答案

应为:

mysqli_stmt_store_result($nameAvailableStmt);
if(mysqli_stmt_num_rows($nameAvailableStmt) == 0)

请参见文档

这篇关于确定是否从准备好的陈述中不返回任何行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 13:11