Your concern is valid, but in this case, the edit was warranted and correct.
The original problem posed in the question was about a reversed order of operands. The answer could do without the code and simply explain that mysqli_query()
takes the connection object as a first argument. The rest is insignificant.
However, the rest of the code was a bad example and it could use some polishing. YCS added the necessary bits and fixed the incorrect logic. The answer is still the same, but the code example is now much better. There was no harm done; only improvement. The edit did not change the original author's intended answer.
If an SME decides to salvage an answer and improve it up to modern standards, you should consider it as a win. The content posted on Stack Overflow is a collaborative effort and if you see someone making a mistake in their answer you can edit it and improve as long as you do not change the meaning. Sometimes this could mean even a big rewrite of the exiting answer. If the original author decides to roll back the improvement, then it is their loss.
The same applies to your answer on that question. Your suggestion was really good, but the code sample was broken. YCS kept the meaning the same and fixed the mistakes.
You should roll back edits if and only if they are harmful or change the intent of the original answerer.