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 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化