我有这个查询:
$consulta = $this->db->consulta("INSERT INTO prestamo_equipo (id_equipo, id_usuario, fecha_devolucion) VALUES $valor ");
其中$valor是(‘1′,’75’,’xs’,’2015-12-14′),(‘1′,’75’,’xs’,’2015-12-14′).
$id = $this->db->getInsertId($consulta);
这最后一行,只返回第一个插入ID,而不是另一个,我想要两个插入的id.
解决方法:
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.
相反,您需要单独插入它们并每次读取最后一个插入ID.
标签:php,mysql,insert
来源: https://codeday.me/bug/20190609/1202142.html