Fixing persistent mysql query issue