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 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥30 用arduino开发esp32控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿