Is taking medicine okay?

I'm 20 weeks pregnant and I've had 3 uti's in the past three months. And my doctor wants to give me a antibiotic everyday until I give birth to stop them from coming back. Has anyone else had the same problem and their baby was born okay?