Insert and Get New ID in Extension
You could do something like CRM_Core_DAO::executeQuery("SELECT LAST_INSERT_ID()");. If your needs are simple that seems like the easiest.

Probably to do it "right", you would use civix generate:entity. See https://docs.civicrm.org/dev/en/latest/extensions/civix/#generate-entity

Then you could do things in an object-y way, like:


$myclass = new MyClass();
$myclass-&gt;field1 = 'foo';
$myclass-&gt;field2 = 'bar';
$myclass-&gt;save();
// Then the inserted id is automatically in $myclass-&gt;id (assuming your auto_increment field is called 'id'