我已经读过MySQL(InnoDB)中的事务是原子的,但是当我在5个线程中测试下一个代码时,他们会选择相同的ID:
$db->beginTransaction();
$row = $db->fetchRow("SELECT * FROM atomic WHERE selected = 0 LIMIT 1");
sleep(5);
$db->update("atomic", array('selected' => 1), "id = " . $row['id']);
$db->commit();
echo "Selected row: " . $row['id'];