Also, your select of the MAX(id) is subject to a race condition - if another user does an insert between the time you insert and you fetch the id, you will get their ID (probably not what you want). The DBI functions should be associated with your statement handles, so you shouldn't have that problem.