Importing CSV into database table not working?

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.