You can use Load data infile
MySQL Query instead of looping through each entry.
Doc: https://dev.mysql.com/doc/refman/8.0/en/load-data.html
For example:
$wpdb->query(
$wpdb->prepare(
"LOAD DATA LOCAL INFILE %s INTO TABLE sas FIELDS TERMINATED BY ',' ENCLOSED BY %s IGNORE 1 LINES (@category,@temple) SET category = @category, temple = @temple;", $_FILES['file']['tmp_name'], '"'
)
);
Make sure that fields from file are properly mapped to those in DB. Also it will change as per your file formatting. Hope this helps.
Note: Please check for syntax error/ typos, code is not tried or tested.
Related Posts:
- What’s the database relationship between a post and its attachments
- Export WP database for import using WP-CLI on Vagrant Box
- Featured image from custom to WordPress database
- Why is my database import losing text widget data?
- How To Export/Import WordPress (MySQL) Database Properly Via Command-Line?
- Best way to import users, post and categories from an external database
- How to create bulk page and content? [closed]
- Importing posts from old website to new conflicting post ID’s?
- When importing database, it shows error
- Is a direct or import approach safer for migration into WordPress?
- MySQL Syntax Error upon restoring database from backup [closed]
- Import live site to local setup without access to live site
- Error establishing a database connection; After importing DB & Theme
- WordPress database import: Row size too large
- Export / import WordPress database
- Bulk-create posts from SQL database
- Exporting table to csv works in the admin but exports HTML data when used on the front end
- Merging two databases without borking it
- Import users from old WP site to new one
- import posts with dutch/special letters
- Connection refused on locahost after importing database?
- Importing Direct to DB – GUID Question
- Best practice to import user base (subscribers) from one website to another?
- Importer fails to import every post
- Undo WooCommerce CSV import
- Import user data using CSV
- WordPress database products structure
- Is it good practice to import/export a blog to test a redesign?
- Realtime database update from 3rd party apps (notion, airtable, sheet, etc)
- How to map data on CSV to web pages?
- Updating database with CSV file and Cron job
- Extracted CSV as Array for Custom Query Loop
- import (migration) user database to wp-users
- Create CSV for import from File directories?
- I broke database after reuploading local version – what exactly happened? Database error
- Importing Concrete5 content to WordPress
- Problem while importing a site in WPLocal: SQL files fail to import
- What is an ORM, how does it work, and how should I use one? [closed]
- What is the difference between an ORM and an ODM?
- What is this JavaScript “require”?
- Rename a table in MySQL
- How should I tackle –secure-file-priv in MySQL?
- What is this JavaScript “require”?
- What is “Advanced” SQL?
- What’s the difference between identifying and non-identifying relationships?
- Can’t connect to MySQL server on ‘127.0.0.1’ (10061) (2003)
- Can’t connect to MySQL server on ‘127.0.0.1’ (10061) (2003)
- Can’t connect to MySQL server on ‘127.0.0.1’ (10061) (2003)
- What are the differences between B trees and B+ trees?
- MySQL SELECT increment counter
- How to resolve ORA-011033: ORACLE initialization or shutdown in progress
- Example of a strong and weak entity types
- How can I import an Excel file into SQL Server?
- Oracle SQL query for Date format
- phpMyAdmin – Error > Incorrect format parameter?
- Create mysql table directly from CSV file using the CSV Storage engine?
- Strange Characters in database text: Ã, Ã, ¢, â‚ €,
- Difference between partition key, composite key and clustering key in Cassandra?
- How SID is different from Service name in Oracle tnsnames.ora
- What is a relation in database terminology?
- Failed to connect to mysql at 127.0.0.1:3306 with user root access denied for user ‘root’@’localhost'(using password:YES)
- Database vs File system storage
- Can I have multiple primary keys in a single table?
- importing a CSV into phpmyadmin
- PG COPY error: invalid input syntax for integer
- Exclude Statement in SQL
- How do you query for “is not null” in Mongo?
- What is a file based database?
- Is it fine to have foreign key as primary key?
- Storing Images in DB – Yea or Nay?
- Using wpdb to connect to a separate database
- how to Optimize WordPress database for 10 million post? [duplicate]
- MySQL Database User: Which Privileges are needed?
- Database synchronization between dev/staging and production
- Keeping WP database synced across multiple developers using git
- WPDB Insert or if exists Update
- Multiple developers / editors working on a site in progress
- How can I make updates to a site, on a development copy, but then move updates back without overriding live site’s evolving database?
- get_results using wpdb
- Will it break my site if I delete all transient records in wp_options table?
- Checking if Database Table exists
- Why WordPress choose data serialization over json_encode?
- What’s the simplest way to backup my WordPress database?
- WordPress (MyISAM) database is slow, should I switch to InnoDB?
- $wpdb won’t insert NULL into table column
- Relaunch 4.2 utf8mb4 database upgrade
- Fastest way (least amount of steps) to locally import a remote database using WP-CLI
- Safest way to bulk delete post revisions
- Please explain how WordPress works with MySQL character set and collation at a low level
- Solution for database version control and deployment?
- The MySQL alternatives: Do Percona Server and MariaDB work well with WordPress, and do they make WordPress go better?
- How many users can WordPress handle?
- Get error messages when $wpdb->insert() returns false?
- Detecting errors generated by $wpdb->get_results()
- Staging sites, how do you manage synchronising updates in the DB?
- Does dbDelta delete columns as well?
- How to get the post publish date outside the loop?
- MariaDB as a backend database
- wpdb update add current timestamp not working
- Site stuck in “Database Update Required” loop