How to get inserted identifiers from multiple INSERTs

I have this query:

$consulta = $this->db->consulta("INSERT INTO prestamo_equipo (id_equipo, id_usuario, fecha_devolucion) VALUES $valor ");

where $valor- ('1', '75', 'xs', '2015-12-14'),('1', '75', 'xs', '2015-12-14').

$id = $this->db->getInsertId($consulta);

this last line, return only the first insert identifier, but not the other, I need the identifier of the two inserts.

+4
source share
1 answer

I am afraid that this is impossible to do. From the MySQL documentation :

If you insert multiple rows with a single INSERT statement, LAST_INSERT_ID () returns the value generated only for the first inserted row. The reason for this is to make it easy to play the same INSERT statement against any other server.

.

+5

Source: https://habr.com/ru/post/1619926/


All Articles