Guillermo
Guillermo

Reputation: 326

how to get inserted ids from several INSERT

i have this query:

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

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

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

this last line, only return the first insert id, but not the other, i want the id of the two inserts.

Upvotes: 4

Views: 67

Answers (1)

TwoStraws
TwoStraws

Reputation: 13127

I'm afraid it's not possible to do this. From the MySQL documentation:

If you insert multiple rows using a single INSERT statement, LAST_INSERT_ID() returns the value generated for the first inserted row only. The reason for this is to make it possible to reproduce easily the same INSERT statement against some other server.

Instead, you'll need to insert them individually and read the last insert ID each time.

Upvotes: 5

Related Questions