PDO::lastInsertId() should return the id of the last inserted row into the database. But sometimes it might return 0. Following are the reasons that could cause this:
- Last executed query was not an insert query
- The query statement was not executed with PDOStatement::execute()
- There is a semicolon at the end of the query