-- Is it true that Bill Gates hit a jackpot in a lottery?
-- Yes, quite true. Only it was not Bill Gates but John Doe, not in a lottery but black jack, not jackpot but $10 and not won but lost.
This "nearly identical" spoils the whole thing. To blame mysqli, you have to run exactly the same query without any assumptions.
There is actually whole PHP program to build your query dynamically. There are surely could be errors in that program. So, if your query runs not the way you expect, you have to verify the result of the program, namely - the very query itself.
Did you ever had an idea to echo the resulting query out, instead of running it? Just to be sure that it is indeed the query you expect? If not - it's time to do so.
And of course it should be exact set of queries, not different from ones you run manually.
If you are indeed running exactly the same static query from mysqli, and result is different from whatever else client - then you are connecting to different servers with these clients. While mysqli will never interfere with your queries. You can be positively sure of that.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…