Hello, folks. I hope you all are well. I was talking to friend about a feature I would like to see in PHP but I mentioned that unfortunately I do not have the knowledge to try implementing it myself, since it is not something very simple, so he mentioned that I could bring this discussion up to this list and see if there would be a person willing to develop that.
The feature is a new method in PDOStatement called addBatch to allow batch INSERTs, exactly like Java's JDBC[1] has. This method would allow us having one single INSERT SQL query, adding multiple values to it, and sending this to the database at once, as one single query. The idea would be something like this: ```php <?php $pdo = // PDO connection $dataRows = ['first value', 'second value', 'third value']; $statement = $pdo->prepare('INSERT INTO table (column) VALUES (?);'); foreach ($dataRows as $row) { $statement->bindValue(1, $row, \PDO::PARAM_STR); $statement->addBatch(); } $statement->execute(); // or ->executeBatch if that's easier ``` Currently, to achieve the same goal, we need to perform string interpolation (or concatenation) to assemble the batch INSERT query and bind every value at once. I have worked on a lot of projects where developers would perform multiple different INSERT queries and if this method existed, it would be a simple change to optimize those pieces of code. As I mentioned, I don't have the knowledge to create the PR myself, but I would be more than happy to help as I can. That includes writing the RFC if it gets to that point (fingers crossed). I am looking forward to hearing back your comments on this. Thank you very much, Vinicius Dias. [1]: https://docs.oracle.com/en/java/javase/20/docs/api/java.sql/java/sql/Statement.html#addBatch(java.lang.String) -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php