That isn't the most comprehensive requirements specification that I have worked from so there is a bit of guesswork involved, such as the comparison criteria being job number and line item matching, and which columns are to be updated from the csv data.
If this is the case, your "production_data" table should have an index on these columns (as my temp table below has).
Anyway, given those caveats, the processing would be along the lines below (4 queries instead of 40,000) and should give you a guide.
<?php
##
## This initial section would normally be in an included file
##
const HOST = 'localhost';
const USERNAME = '???';
const PASSWORD = '???';
const DATABASE = '???';
function pdoConnect($dbname=DATABASE)
{
$db = new PDO("mysql:host=".HOST.";dbname=$dbname;charset=utf8",USERNAME,PASSWORD);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$db->setAttribute(PDO::MYSQL_ATTR_LOCAL_INFILE, true);
return $db;
}
##
## Connect to DB server
##
$db = pdoConnect();
##
## create a temporary table to store the csv data
##
$db->exec("CREATE TEMPORARY TABLE production_csv (
id int not null auto_increment primary key,
enterprise tinytext,
part_num text,
description text,
qty int,
line_item varchar(11),
job_num int,
work_order varchar(50),
psm varchar(50),
date_change_flag tinyint,
scheduled_ship_date date,
on_hold tinyint,
on_hold_reason varchar(50),
total_hours decimal(10,2),
worfc varchar(50),
INDEX job_line (job_num, line_item)
)");
##
## load the csv data into the table
##
$db->exec("LOAD DATA LOCAL INFILE 'prod_data.csv'
INTO TABLE production_csv
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
IGNORE 1 LINES
(@dummy, @dummy, enterprise, part_num, desc, qty, line_item,
job_num, work_order, psm, date_change_flag, scheduled_ship_date,
on_hold, on_hold_reason, total_hours, worfc)
");
##
## write matching production_data records to archive
##
$db->exec("INSERT INTO production_archive
SELECT pd.*
FROM production_data pd
JOIN
production_csv USING (job_num, line_item)
");
##
## update the production_data table from the production_csv table
##
$db->exec("UPDATE production_data d
JOIN
production_csv c USING (job_num, line_item)
SET d.enterprise = c.enterprise,
d.part_number = c.part_num,
d.description = c.description,
d.qty = c.qty,
d.as400_ship_date = c.scheduled_ship_date,
d.hold_status = c.on_hold
")
?>