我有这个代码。直接运行它应该返回100。但是有了这个代码,它返回1。我是否使用 ?错了,或者为什么它只返回1? <?phprequire '../notWebsite/dbh.php';session_start();$userID = (int)$_SESSION['userID'];$sqlCount = "SELECT COUNT(groupID) FROM savedbyuser WHERE userID = ?";$stmt = mysqli_stmt_init($conn);if(!mysqli_stmt_prepare($stmt, $sqlCount)) {header("Location: ../GymnasieArbeteHemsida.php?error=countError"); exit();}else {mysqli_stmt_bind_param($stmt, "i", $userID);mysqli_stmt_execute($stmt);$count = mysqli_stmt_execute($stmt);echo $count; exit();}mysqli_stmt_close($stmt);mysqli_close($conn);?>
1 回答
白衣非少年
TA贡献1155条经验 获得超0个赞
如手册 https://www.php.net/manual/en/mysqli-stmt.execute.php 所述
Returns TRUE on success or FALSE on failure.
所以这个
$count = mysqli_stmt_execute($stmt); echo $count;
转换为
$count = true; echo $count; // print 1
在手动聚焦上
Note: When using mysqli_stmt_execute(), the mysqli_stmt_fetch() function must be used to fetch the data prior to performing any additional queries.
导致 https://www.php.net/manual/en/mysqli-stmt.fetch.php 等等...
- 1 回答
- 0 关注
- 73 浏览
添加回答
举报
0/150
提交
取消