Yep, I'm not going to lie. I didn't read through your code at all since I assumed you have a normalization issue.
If you have a normalized database, and you are still regularly issuing DDS', than that's fine. I can't see a reason for it even across platform; all that matters is that its normalized. But to me, constantly altering the structure does reek of a normalization issue.
header('HTTP/1.1 420 Enhance Your Calm');