Use mysql_insert_id() instead of SQL
Do not fail on last insert id failure on custom schema.