我一直试图解决这个问题。我厌倦了回应mysql查询中返回的行数
$linkTow = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
$getVotesSQL = "SELECT null FROM votes WHERE `idgame` = ?";
$getVotesStmt = $linkTow->prepare($getVotesSQL);
$getVotesStmt->bind_param("s", $idGame);
$getVotesStmt->execute();
echo $getVotesStmt->num_rows;
$getVotesStmt->close();
$linkTow->close();
我总是得到0.
答案 0 :(得分:0)
如果您真的更喜欢使用$linkTow->prepare
,那么这是正确的方法:
$getVotesSQL = "SELECT null FROM votes WHERE `idgame` = ?";
$getVotesStmt = $linkTow->prepare($getVotesSQL);
$getVotesStmt->bind_param("s", $idGame);
$getVotesStmt->execute();
$getVotesStmt->store_result(); // <- IMPORTANT
echo $getVotesStmt->num_rows;
$getVotesStmt->close();
$linkTow->close();
之前您正在做的是$linkTow->query
<强> MANUAL 强>