A very simple function to perform bulk SQL inserts, since WPDB doesn't provide one directly. The aim is for simplicity - both in the function itself, and in using it - rather than being a massive beast which covers all possible incorrect usage scenarios. Provide it with clean, consistent data, and it should hopefully be able to do what you want without issue.
Notes:
- Provide a table name and an array of associative arrays of rows to insert
- Column names are pulled from the first row of data automatically
- Make sure you provide the same fields in each row (there's no protection for this)
- Data types (for WPDB placeholders) are auto-detected for each individual value (using
is_numeric()
) - There is no protection for exceeding maximum query size (i.e. MySQL's
max_allowed_packet
); you could pre-batch into smaller "safe" chunks if you need to handle this case - or just find a better way to insert such a large amount of data