Medication causing UTI

About 2 weeks ago I was put on metaformin by my gynecologist. Past few days it’s burned when I peed so I went to my primary care doctor today to be tested for a UTI. It came back super positive for infection and I had blood in my urine. He asked me if I had been put on anything and I told him metaformin. He said it probably caused my UTI and if this becomes a reoccurring thing that I should be taken off of it. So... what does that mean? The metaformin is to help treat my PCOS essentially and I’m also prediabetic. Any idea of what an alternate treatment would be??