获取成功更新mysql的确认

时间:2019-05-07 17:32:18

标签: php mysql pdo

我正在用PHP为正在构建的桌面程序构建API。如果选择语句如下所示,我已经创建了一个嵌套的更新;我试图回应是更新了1行还是更新了0行(可能是由于我的嵌套语句)

function Savetimes($RID, $uid, $curtoken, $PSAP, $DispatchNotified, $Dispatched, $Confirm, $Enroute, $Onscene, $ArrivedPt, $TransferPt, $Transporting, $ArriveDestination, $TransferCare, $Cleared, $Canceled) 
    try {
        $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
        // set the PDO error mode to exception
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    }
    catch(PDOException $e) {
        //  echo "Connection failed: " . $e->getMessage();
    }

    $statement = $conn->prepare("UPDATE `Appointments` 
                SET `PSAP` = :PSAP, 
                    `DispatchNotified` = :DispatchNotified, 
                    `Dispatched` = :Dispatched, 
                    `Confirm` = :Confirm, 
                    `Enroute` = :Enroute, 
                    `Onscene` = :Onscene, 
                    `ArrivedPt` = :ArrivedPt, 
                    `TransferPt` = :TransferPt, 
                    `Transporting` = :Transporting, 
                    `ArriveDestination` = :ArriveDestination, 
                    `TransferCare` = :TransferCare, 
                    `Cleared` = :Cleared, 
                    `Canceled` = :Canceled 
                WHERE `RID` = :RID 
                and (
                        (
                            SELECT count(*) 
                            From `Token` 
                            WHERE ukey = :ukey 
                            AND uid = :uid 
                            AND TimeExp >= now() 
                            AND TTL > 0
                        ) > 0)
                ");

    $statement->execute(array(
        "PSAP" => $PSAP,
        "DispatchNotified" => $DispatchNotified,    
        "Dispatched" => $Dispatched,
        "Confirm" => $Confirm,
        "Enroute" => $Enroute,
        "Onscene" => $Onscene,
        "ArrivedPt" => $ArrivedPt,
        "TransferPt" => $TransferPt,
        "Transporting" => $Transporting,
        "ArriveDestination" => $ArriveDestination,
        "TransferCare" => $TransferCare,
        "Cleared" => $Cleared,
        "Canceled" => $Canceled,
        "RID" => $RID,
        'ukey' => $curtoken,
        'uid' => $uid
        ));
    $UpdateCount = $statement->rowCounts();

    return $UpdateCount;
}

进一步解释更新语句:约会将使用通过API提供的数据进行更新(我简化了代码,以在更新语句之前删除了大约100行数据处理)。仅当搜索未过期令牌匹配的嵌套Select语句计数超过0行时,它才会更新。

我的流程无法计算更新的行-我们将为您提供任何帮助。

0 个答案:

没有答案