I'm sorry if there is already a thread asking this question, I searched but wasn't really sure of what keywords to use. Anyway, this is my question.
What I need to do is somehow retrieve an automatically incremented primary key from a row that I just inserted. So something like, if a user just posted a comment, the PHP script could tell them that, "Your comment's ID is $comment_id" (Made up situation).
Id there a way to do this? I've gone through multiple ideas, first of all counting the number of existing rows, but if I had deleted a row for whatever reason it would return the false id, and then I'd have to make a "deleted" field, which would just make things mre complicated than I need. The other one was to randomly generate a code for the inserted row, and then do another query which would retrieve the ID based on that code, but that just make another necessary query, and seems like a horrible way to build code.
So there must be some way to return that variable. Help?