Using insert ID

It’s very common to insert data in multiple tables: a book followed by its author, a customer followed by their purchase, and so on. When doing this with an autoincrement column, you will need to retain the insert ID returned for storing in the related table.
For example, let’s assume that these devices can be “sold” to a person. New device is stored in the device table, we also want to create a key to tie it to the device to a owner. The code to do this is similar to that in, except that the returned insert ID is stored in the variable $insertID and is then used as part of the subsequent query

Now the cat is connected to its “owner” through the devices unique ID, which was created automatically by AUTO_INCREMENT.

Example for insert

Leave a Reply

Your email address will not be published. Required fields are marked *