I am building an API in PHP for a desktop program I am building. I have created a nested update if select statement as provided below; I am trying to respond if 1 row was updated or 0 were updated (likely due to my nested statement)
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;
}
to further explain the update statement: The Appointment will be updated with data provided through the API (I simplified the code to remove about 100 lines of data processing before the update statement). It will Only update if the nested Select statement searching for an unexpired token match counts more than 0 rows.
My process is failing to count the updated rows - any assistance is appreciated.