I'm defining variables in the following way, according to this SO answer :
$sql = "SET @update_id := '', @update_name := '';
UPDATE table SET status=?, id=(SELECT @update_id:=id), name=(SELECT @update_name:=name)
WHERE status=? AND id>? ORDER BY id ASC LIMIT 1;";
$stmt = $db->prepare($sql);
$stmt->execute(array(1, 0, $curRow));
and then accessing them in a successive query:
$stmt = $db->prepare('SELECT @update_id, @update_blogid');
$stmt->execute();
This is used to mark a row while it is being updated. The table is large, and so there are a couple simultaneous scripts running, to help speed it up.
If the scripts are identical, but on two different processes initiated by a cron job, do they have access to each other's user-defined variables?
For instance, could a second process update the values set by the first process, before the first process was able to read the values?
User-defined variables are session-specific. A user variable defined by one client cannot be seen or used by other clients.
So maybe the root of the question is: are two separate processes, initiated by the same cron job, considered separate clients?
Otherwise, my best thought is to initialize a random number when the script opens, and tack it to the end of each variable name:
$rand = rand(100, 999);
$sql = "SET @update_id". $rand ." := '', @update_name". $rand ." := ''; ...";
But would prefer not to, if I can help it. Even if the messy fix solves it, the answer to this will be good knowledge to have in the back pocket.