3
I have a default function that I use for all of 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 lines in one query INSERT INTO table (campo, campo2) VALUES (:campo, :campo2), (:campo, :campo2)..
But I do not know how I should proceed so that the function can do this treatment and perform the inserts.
It does not need to be modified the existing function, I can create a unique one for this use, but the problem is that I do not know how to assemble the structure so that dear group of values to be inserted goes through bindParam
.
Seria that ?
– rray
@rray great! I’m making a Query Builder library in PHP, I’ll take this tip.
– Wallace Maxters
@rray more or less... But I managed to understand the logic and I can solve here! Vlw!
– celsomtrindade
@Wallacemaxters body library Builder?
– rray
@Wallacemaxters see if the answer also helps in something ;)
– celsomtrindade
http://answall.com/questions/174354/como-inserir-todos-valores-do-array-e-evitar-query-execute-a-cada-execu%c3%a7%c3%a3o-d/174356#174356
– Antonio Alexandre