duano3557 2018-11-21 15:06
浏览 56

PDO事务中受影响记录的计数

I have a script that runs a pretty basic PDO transaction and it doe work (selects records and performs the merge based on those results)

So it successfully inserts/updates but I'm trying to get a count of accurate records and it doesn't work, it just returns 1 in powershell.

Starting with an empty database table and running this script, It inserts 1300 records successfully but $count prints '1'. I'm simply trying to get record counts, success messages and errors for the purpose of an email when the script runs. Am I missing something?

while($arr = odbc_fetch_array($result)){

    $stmt = $PDO->prepare("
        MERGE INTO ORDER_STATUS as S
            USING (VALUES(
                        CAST(:ORDER_ID as INT),
                        CAST(:ORDER_STATUS as VARCHAR(45)),
                        CAST(:is_active as DECIMAL(1,0)),
                        CAST(:DATE_UPDATED as DATE)
                        )
                    )
            AS O(order_id, order_status, is_active, date_updated)    
            ON O.order_id = S.order_id  
        WHEN MATCHED THEN UPDATE SET order_status = O.order_status, is_active = O.is_active, date_updated = O.date_updated
        WHEN NOT MATCHED THEN INSERT(order_id,order_status,is_active,date_updated) VALUES(O.order_id, O.order_status, O.is_active, O.date_updated)
    ");

    $PDO->beginTransaction();
    $i = 0;
    while($db2row = odbc_fetch_array($result)) {

        if(++$i % 1000 == 0) {
            $PDO->commit();
            $PDO->beginTransaction();
        }
        $stmt->execute($db2row);
    }
    $PDO->commit();
    $count = $stmt->rowCount();
    print_r($count);
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 乘性高斯噪声在深度学习网络中的应用
    • ¥15 运筹学排序问题中的在线排序
    • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
    • ¥30 求一段fortran代码用IVF编译运行的结果
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥30 python代码,帮调试,帮帮忙吧