PHP & MySQL – Generate own unique reference

I am currently coding a web application which I will need to create unique reference for quotes and invoices.

I wanted to create a reference that included the year and month then an reference number. i.e YYYY-MM-001.

The web application will be multi tenant and several users will be using it at the same time. One of my concerns is, how would I generate my reference without it be duplicated at the same time if there is multiple users doing the same request at the same time?

What would be the best way for me to approach this?

I am using PHP 8 and a MySQL database.