Determining if no rows are returned from a prepared statment

夙愿已清 提交于 2019-12-24 03:14:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!