doujing6053 2015-04-28 18:31
浏览 50

mysqli_stmt_affected_rows不适用于update prepared语句

I have this code

$SQL = "UPDATE cart SET a = ? WHERE b = ? AND c = ?";

            if($stmt2 = mysqli_prepare($conn, $SQL )){
                        mysqli_stmt_bind_param($stmt2, "iii", $a1, $b1, $c1);
                        mysqli_stmt_execute($stmt2);

                if(mysqli_affected_rows($conn)){
                    echo "updated";
                    mysqli_stmt_close($stmt2);
                }
                else
                    echo "nope";
            }

I was figuring out why above code never work. I have debug every way that I know.

Lastly I delete the if condition. Somehow, it is working. Tried to browse on the internet to figure out what is the cause but did not find any. Can somebody please explain to me why does it happen so? I am a newbie to mysqli. Really need help :) thanks!

  • 写回答

1条回答 默认 最新

  • doudun1029 2015-04-28 18:38
    关注

    You should be using

    mysqli_stmt_affected_rows($stmt2);
    

    mysqli_stmt::$affected_rows -- mysqli_stmt_affected_rows — Returns the total number of rows changed, deleted, or inserted by the last executed statement

    Instead of

    mysqli_affected_rows($conn);
    

    which is for plain query executions.

    Manual

    Edit

    I just noticed that your question title mentions the right function name, and your code uses the wrong one.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度