A naive question - why not create a wrapper function or method called get_unique_id and change the implementation based on the backend in use? For MySQL, you would just need to insert an empty row using the AUTO_INCREMENT behavior - for other db's, you might need some combination of locking or dummy INSERT statements, but it would at least be portable.