Is there a function to get the last generated MySQL record Id

Basically doing something like this

1. Enter book details

2. Details written to file with a MySQL auto generated key.

Now want to add

1. Borrowers of the book wtih the auto generated key identifiying which book a borrow has gpt their grubby hands on.

We are trying to determine via an online system which genre of books are the most popular with which sections of a school.

Hope that makes some sort of sense.