The lastInsertId() method returns the ID of the last inserted row or a sequence value automatically
generated by the database (typically via AUTO_INCREMENT). This is crucial in situations where, after
inserting data into one table, you need this unique ID to link with other tables in the database. The method operates
directly on the connection object rather than on a prepared statement.
Practical Application: We call this method immediately after a successful INSERT
command. If the insertion was unsuccessful or if the table does not have automatic key generation enabled, the method
will return 0 or the string "0". Check the process at home by following these steps:
users table has its id column set to
AUTO_INCREMENT.