0

Well , i´ve got a problem with bindparam insertion

$sql="INSERT INTO $tabla (value1,value2,value3)";

for($arrays as array){
  $sql.=",($array,:bind2,:bind3)"
}
$stmt=conection::conect()->prepare($sql);
$stmt->bindParam(:bind2, $data2);
$stmt->bindParam(:bind3, $data3);
$stmt->execute();

What i´m looking for is to build somethig like that

 INSERT INTO $table (value1, value2, value3) 
 
  VALUE (array[0],:bind2,:bind3),
        (array[1],:bind2,:bind3),
        (array[2],:bind2,:bind3)

, as you can see the first value is inserted throught a for loop and the others values (value2 and value 3) are the same bind baram, it means that only value1 will change when i do the insertion, but for some reason it only inserts the first value and it doesn´t execute all the query. I hope you can help me guys. (Sorry for my english)

  • Does this answer your question? [Best way to INSERT many values in mysqli?](https://stackoverflow.com/questions/15149157/best-way-to-insert-many-values-in-mysqli) – El_Vanja May 06 '21 at 16:20
  • Please note that the code in your question has syntax errors. It's always better to copy and paste actual code, rather than re-typing it. – El_Vanja May 06 '21 at 16:21
  • 1
    And aside from that, what is you reasoning behind not binding the first parameter? – El_Vanja May 06 '21 at 16:22
  • Does this answer your question? [PDO Prepared Inserts multiple rows in single query](https://stackoverflow.com/questions/1176352/pdo-prepared-inserts-multiple-rows-in-single-query) – greenjaed May 06 '21 at 21:15
  • El_vanja man, it´s because the nature of the query, i need to reuse the bind params except for the first one (according to the example i posted), and yes i´ll take in mind the next time to post the original code, i just didi it in that way because i thought it was easier. – user15854983 May 08 '21 at 16:00
  • @greenjaed, no it doesn´t, or at least not as I want, I thought it could be a kind of easier because in that example they build the query by creating multiple bind params according to one array and well, i wanted to avoid doing it in that way because the values of the bind params are the same for all the queries and doing by that way ii wouldn´t be reusable, at least in my opinion. – user15854983 May 08 '21 at 16:11

0 Answers0