in reply to SELECT LAST_INSERT_ID does not work

As others have pointed out, this is a per-connection function, so if there are multiple clients, that may be affecting it. Also, triggers or the like that grab a new id (even if left unused) may b affecting it.

One kludge, perhaps, to guarantee it to work, would be to use a stored procedure to do the insert, run the select, and return the result from the select to you.