drde3456 2016-02-16 19:05
浏览 32

MySQL语句在phpmyadmin中工作,但在代码中不起作用

I have the following piece of code. It works when executed in the sql interface of phpmyadmin but when I execute it on the server $stmt = $con->prepare($sql) always returns false and I exit with an error.

Note that $stmt = $con->prepare($sql) does not return an error messages. I'm afraid I might be doing something wrong here too?

I assume I'm missing something important here!

Also the Update statement worked correctly before I modified it to return a comma separated list of updated IDs.

$sql = "SET @uids := null;
                    UPDATE userpicks, brackets
                    SET userpicks.player1 = ?, userpicks.pick = ?
                    WHERE userpicks.id_user = ? AND userpicks.id_tournament = ? AND brackets.stage > ? AND userpicks.player1 = ?
                    AND ( SELECT @uids := CONCAT_WS(',', brackets.id, @uids) );
                    SELECT @uids;";

        if ($stmt = $con->prepare($sql)) {
            $stmt->bind_param('iiiiii', $noPlayerID, $noPlayerID, $_SESSION ["id"], $id_tournament, $bracket_stage, $id_player);
        } else {
            echo mysqli_error($con);
            return getJSONArrayError("Error occurred");
        }
  • 写回答

1条回答 默认 最新

  • dongxianrang9269 2016-02-16 19:13
    关注

    I think you are mixing up Procedural and OOP approach in PHP http://php.net/manual/en/mysqli.quickstart.dual-interface.php Try $stmt=mysqli->prepare($con,$sql) instead of ($stmt = $con->prepare($sql))

    评论

报告相同问题?

悬赏问题

  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测