Use precalculated next_ph_num.
Add insert_all/3 and prepare_insert_all/3 funs.