问题
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)
回答1:
It should be:
mysqli_stmt_store_result($nameAvailableStmt);
if(mysqli_stmt_num_rows($nameAvailableStmt) == 0)
See the Documentation
来源:https://stackoverflow.com/questions/17054131/determining-if-no-rows-are-returned-from-a-prepared-statment