I have a default function that I use for all my inserts (when they only have 1 insert at a time), which would be:
insereRegistro($sql, $param=NULL) {
$query = $conn->prepare($sql);
//Converte os parâmetros para bindParam
if ( isset($param) ) {
foreach ($param as $key => $value) {
$$key = $value;
$query->bindParam($key, $$key);
}
}
$query->execute();
$response = $conn->lastInsertId();
}
But I would like to insert several rows in a same query INSERT INTO table (campo, campo2) VALUES (:campo, :campo2), (:campo, :campo2)..
But I do not know how to proceed so that the function can do this processing and execute the inserts.
I do not need to modify the existing function, I can create a unique one for this use, but the problem is that I do not know how to mount the structure so that the group of values to be entered passes through bindParam
. >