Build PHP queries automatically