Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120569 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 88867 invoked from network); 13 Jun 2023 23:41:31 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 13 Jun 2023 23:41:31 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CC847180340 for ; Tue, 13 Jun 2023 16:41:30 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 13 Jun 2023 16:41:30 -0700 (PDT) Received: by mail-qt1-f171.google.com with SMTP id d75a77b69052e-3f9b8f1c2fdso12320241cf.2 for ; Tue, 13 Jun 2023 16:41:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686699689; x=1689291689; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=jJEjzMxTj5R3OhylAZJUOO2OpvkVQo0eA+iDV4HsEl8=; b=bRXS41eWgxVpnKN/0x2uVO/AfywB+8KXt6iSbOJYINGjVDFgS9Yf8N2ldLQ+Jgjc7h zidVlGMIJlk8JrCeCsT3RlgIrHTb67x56rSrPiFE3Rn8OQDNpZNHBaZtm+XuBUhcfCqE TKAUGHHRT2t3H74NYOMWPtuGZA2iSEwcVvc1Uab1EFmFLRqdwrQD/AnuInBy4j4hErZE T4qmOrpTFCFsZFNvKMKH9WnZQ+wcJdFjBXzaA3pQRkaG1IOaiB1Qio5MI2MVx9gvVory mDwxLeXkHnh7EtDe2QAXGwtEeTrJWd9B0fAuflF7UMITXmvWPjd5Y5UEboo9FiCBl+k5 TNQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686699689; x=1689291689; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=jJEjzMxTj5R3OhylAZJUOO2OpvkVQo0eA+iDV4HsEl8=; b=JG8n25U5nh3KBva/QmX3NQqw+yD7hvJChQGqUvKqu3iDeFIjyL3w6qViLujkeClqlt oPEAq5j9syEiLCMRCsLIwkFoysjGlVvVR8t99LMYvGNNijsoYCu540ytO0/xpukfVa6r cCj2t9FV+7ebxEm2q0BaLTwxfP7G1oha/qQ2BpMwU2PFblBzEbOv7mAIRNkQICbB9vvI akGgTQ+V/0N3XHcjjyncyveoAdG3el2NYhtGSgFGxh5cMUq/K6Ls8NTdZJgWI0VeJ1Jm 9egcBS62ERzlMqjc96Ga0/Sm4iZp+Bqq9CQrW3DHrDeNYfVRsYSg6QyJAKkckzZZZoMD 2EyA== X-Gm-Message-State: AC+VfDzroIAnzrDHgvONjJECWPVJRxFhTzH5Z3D8eMuKpoZXZkhSpPEE Dz61MCDqKa2Uy9k7JcHTVy32oNPhMge4hK23uzUBrxjagYkX2g== X-Google-Smtp-Source: ACHHUZ7cwYLwIDA0/eisCjxPN5amUMHXgqUHAwKF6ElKTujA6XUgwnmpF+Y2W5wEgFeNC93vM4+/23eNlWqowTPF6NY= X-Received: by 2002:ac8:5b05:0:b0:3f5:3d3d:d1b5 with SMTP id m5-20020ac85b05000000b003f53d3dd1b5mr383633qtw.27.1686699689464; Tue, 13 Jun 2023 16:41:29 -0700 (PDT) MIME-Version: 1.0 Date: Tue, 13 Jun 2023 20:41:18 -0300 Message-ID: To: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Subject: Possible RFC: PDOStatement::addBatch From: carlosv775@gmail.com (Vinicius Dias) 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 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)