dtnmnw3697 2017-04-16 15:05
浏览 82
已采纳

SQL Count无效

First thing to say is I am somewhat new to the whole SQL prepared statment thing. Here is my issue, when I try and count the number of times a user has rated a post I am not getting a response, instead I get an odd error. Any help would be appreciated.

$query = "SELECT COUNT(*) FROM `rate` WHERE `userID`=? AND `postID`=?";
        if($stmt = $connection->prepare($query)){
            $stmt->bind_param("ii", $id, $post_id);
            $stmt->execute();
            $stmt->bind_result($count);
            $stmt->fetch();
            echo $count;
        } else {
            echo $connection->error;
        }

And the error given by the echo $connection->error is: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1

  • 写回答

1条回答 默认 最新

  • douzhi1919 2017-04-16 15:19
    关注

    As stated by @Fred-ii ->

        `COUNT(*) AS totalcount` then bind result on $totalcount
    

    it's also important to have error_reporting(E_ALL); ini_set('display_errors', 1); on top of pages in pre-prod

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于这个问题的算法代码
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据