We work through PDO with mysql, it is very important. I do as here http://php.net/manual/ru/pdo.prepared-statements.php

$stmt = $dbh->prepare ("INSERT INTO user (firstname, surname) VALUES (:f-name, :s-name)"); $stmt -> bindParam(':f-name', 'John'); $stmt -> bindParam(':s-name', 'Smith'); $stmt -> execute(); 

How can I send a lot of inserts, 100 in 1000 pieces?

Something I can not understand about the procedure

you know how in mysql you are combing INSERT INTO user () VALUES (), (), (), ();

  • It is necessary to write a crutch, which creates a string with prepared parameters, and then passes them to the execute array. There is no built-in solution; you can find a library or solutions on the Internet (multiple insert pdo). - Firepro
  • Why do you exclude the option of sequential execution? I understand that there will be a gain in speed, but does it really mean anything to you? - etki
  • Well, the last option is already working. Just by analogy, I look. Bundles faster inserts. Although not measured by how much. Right now I measure in phpadmin and I can decide maybe not that much of a win - Alex Lizenberg

1 answer 1

Pdo has transactions and prepared expressions.

http://php.net/manual/ru/pdo.commit.php

 $dbh->beginTransaction(); /* Вставка мноТСства записСй ΠΏΠΎ ΠΏΡ€ΠΈΠ½Ρ†ΠΈΠΏΡƒ "всС ΠΈΠ»ΠΈ Π½ΠΈΡ‡Π΅Π³ΠΎ" */ $sql = 'INSERT INTO fruit (name, colour, calories) VALUES (?, ?, ?)'; $sth = $dbh->prepare($sql); foreach ($fruits as $fruit) { $sth->execute(array( $fruit->name, $fruit->colour, $fruit->calories, )); } /* Ѐиксация ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠΉ */ $dbh->commit(); 

But I'm not sure this will help.

  • one
    Well, it's more like the answer in essence. I will try. if not that means nothing will help. thanks - Alex Lizenberg
  • It’s not very clear what the "mysql library" is about, but in the PDO emulation mode it is fine to send multiple requests. Another thing is that the author needs a plural insert - Ipatyev
  • I support the answer - a pack of inserts / updates through a transaction is much faster than a pack of inserts / updates without a transaction. - Goncharov Alexander
  • @GoncharovAlexander, firstly, this is true only for innodb with default settings, and secondly, there is also a third option, described by the author of the question. - Ipatiev