Insert multiple values with MySQL->insert() by passing multiple arrays #44

Open
opened 2025-01-30 13:48:38 +01:00 by vlw · 0 comments
vlw commented 2025-01-30 13:48:38 +01:00 (Migrated from codeberg.org)

In order to insert multiple rows at once into a table, right now, you have to loop over each row can call MySQL->insert() on each.

Example:

$db = MySQL->for("table");

foreach ($rows as $row) {
    $db->insert($row);
}

When I think it would be nice to accept both an assoc array as a single row (current behavior), or multiple arrays as n arguments to insert each.

$db->for("table")->insert(...$rows);

The simplest way to achieve this I guess would be to loop through this block for each row
codeberg.org/vlw/php-mysql@c64eb96049/src/MySQL.php (L254-L264)

In order to insert multiple rows at once into a table, right now, you have to loop over each row can call `MySQL->insert()` on each. Example: ```php $db = MySQL->for("table"); foreach ($rows as $row) { $db->insert($row); } ``` When I think it would be nice to accept *both* an assoc array as a single row (current behavior), or multiple arrays as n arguments to insert each. ```php $db->for("table")->insert(...$rows); ``` The simplest way to achieve this I guess would be to loop through this block for each row https://codeberg.org/vlw/php-mysql/src/commit/c64eb96049907da60dc9f237d26aef0e531b0015/src/MySQL.php#L254-L264
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
vlw/php-mysql#44
No description provided.