PDO交易中受影响的记录数

时间:2018-11-21 15:06:14

标签: php sql pdo db2

我有一个运行基本PDO事务的脚本,它可以正常工作(选择记录并根据这些结果执行合并)

所以它成功地插入/更新了,但是我试图获取准确的记录数,但它不起作用,它在powershell中只返回1。

从一个空的数据库表开始并运行此脚本,它成功插入1300条记录,但是$count打印'1'。 我只是想在脚本运行时获取记录数,成功消息和错误,以用于发送电子邮件。我想念什么吗?

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 个答案:

没有答案