yes, of course, don't worry about that, but you should definitely ask lastInsertId right after the insert request. At the same time, another request should not be executed on this connection, each PHP process should have a separate connection.
Also, if you think that a table will have hundreds or thousands of attachments per second, consider not using indexes or using a minimum amount of indexes. In case MySQL supports MyISAM tables.
source share