In a PHP + MySQL application in which I need to store as many likes + id's of who I gave in a post, I came to doubt the logic.
Assuming 2 users give like in the same post at the same time, and both execute:
UPDATE te_anuncios
SET curtidasTotal = curtidasTotal + 1,
curtidasIds = curtidasIds + idNovo; //iria geral algo como '23, 31, 43, 44, 32...'
I need to handle this update in PHP, to add the ID of the new tanner, right?
<?php
$idsAtuais .= ", {$_SESSION['userId']}";
My fear is that while PHP handles the current IDs to concatenate the database string, someone else takes a liking and captures the values of the database without the ID being treated and overrides it when it completes.
Would there be a smarter way that would inhibit this problem? Maybe run something directly in MySQL.