I insert invoice data in sale_invoice table, then I need the id value to insert the sold product to sold_items with invoiceid.
How to get last inserted id after insert the invoice data?
I use zeosdb and mariadb.
Well in a properly designed database, the auto inc field should be a candidate key used for fast loading of records, so you should use that actual primary key to return it.
Failing that would be best to use an insert/return statement...
And the least preferred option is to query the last used id. But in environments with a high degree of concurrency managed by professionals, that may occasionally fail I have seen it in banking and the travel industry. But it is probably good enough in most cases.