Can bladder infections cause miscarriage?

So I was at the ER due to having some cramping. I’m 21 weeks pregnant. They did an ultrasound and a urine sample. And blood work. After my results, they told me I had a little bit of bladder infection that could almost lead to a miscarriage. I’m scared you don’t want to lose my baby. How many mamas went through this. And everything goes fine after curring it with prescription???