我用PHP Slim Framework开发了一个Web服务,该服务在MySQL数据库中选择一行。该Web服务由用户调用,实际上,如果两个用户同时调用该Web服务,则返回同一行。
我尝试了«FOR UPDATE»语句,但是它不起作用。我正在将MySQL 8与InnoDB引擎一起使用。
$sql = "SELECT tasks.id, tasks.idEmail
FROM tasks
LEFT JOIN results ON tasks.idResult = results.id
WHERE tasks.idAgent = $agentId AND results.personnal = 1 AND tasks.callbackHour <= CURTIME() AND tasks.callbackDate <= CURDATE() AND tasks.idCampaign = $idCampaignToDistribute AND tasks.idResult <> 9999
UNION
SELECT tasks.id, tasks.idEmail
FROM tasks
LEFT JOIN results ON tasks.idResult = results.id
WHERE results.personnal = 0 AND results.recall = 1 AND tasks.callbackHour <= CURTIME() AND tasks.callbackDate <= CURDATE() AND tasks.idCampaign = $idCampaignToDistribute AND tasks.idResult <> 9999
UNION
SELECT tasks.id, tasks.idEmail
FROM tasks
WHERE tasks.idCampaign = $idCampaignToDistribute AND tasks.idResult = 0 $customFilter
LIMIT 1";
$stmt = $db->query($sql);
$idsToDistribute = $stmt->fetchAll(PDO::FETCH_OBJ);
现在,我想避免网络服务选择同一行。我该怎么办?
有什么想法吗?