Welcome Guest, Not a member yet? Register   Sign In
Looped Insert changes to Select
#1

Ok, this one has me baffled. Hopefully someone out there can help because I am out of ideas. I have a file I am importing, reading each line, manipulating and inserting into a table. It runs fine for 584 lines and the suddenly the INSERTS become SELECTS! 
I have tried removing the first 584 lines from the csv file and it did the same thing (although at a different line number). I tried removing just 500 lines to leave the last valid line to see what would happen. That time it ran 800 or so lines before switching, so I don't think it is data.

Data Sample (with the full file it is failing on the line starting with 1192):
Code:
1188,"08990",1,"Fast Voip Us",,,"AT&T","89014104272936908990",,"5306918987","6003474FF6CE",1,2020-08-27,,1,"152971","Joel",,0,0,,,,
1189,"08982",1,"Fast Voip Us",,,"AT&T","89014104272936908982",,"5306919020","6003474DBBD2",1,2020-08-27,,1,"144001","Joel",,0,0,,,,
1190,"06903",1,"Fast Voip Us",,,"AT&T","89014104272936906903",,"5306918954","6003474B5143",1,2020-08-27,,1,"135851","Joel",,0,0,,,,
1191,"06911",1,"Fast Voip Us",,,"AT&T","89014104272936906911",,"5306918955","6003474B7187",1,2020-08-27,,1,"135161","Joel",,0,0,,,,
1192,"06929",1,"Fast Voip Us",,,"AT&T","89014104272936906929",,"5306919107","6003474DBEDF",1,2020-08-27,,1,"129501","Joel",,0,0,,,,
1193,"06937",1,"Fast Voip Us",,,"AT&T","89014104272936906937",,"5306918956",,1,2020-08-27,,1,"6600AEL",,,0,0,,,,
1194,"07018",1,"Fast Voip Us",,,"AT&T","89014104272936907018",,"5306918972","6003474ad6a3",1,2020-08-27,,1,"129991","Joel",,0,0,,,,

Code Sample:
PHP Code:
while (($filedata fgetcsv($file5000",")) !== FALSE) {
// Skip first row
if($i 0) {
    //Add a card record
    $data = array(
        'vendor_id'            => $vendors[strtolower(trim($filedata[3]))],
        'carrier'            => $filedata[6],
        'card_num'            => $filedata[7],
        'mdn'                => $filedata[9],
        'macid'            => $filedata[10],
        'invoicenum'        => $filedata[5],
        'cost'                => ($filedata[4] ? $filedata[4]*1.00 0.00),
        'location'            => 'lo-p3zd82dgjj',
        'notes'            => $filedata[20],
        'badcard'            => $filedata[18],
        'date_purchased'    => date("Y-m-d",strtotime('2016-01-01')),
        'date_activated'    => date("Y-m-d",strtotime($filedata[12])),
        'date_deactivated'    => ($filedata[13] ? date("Y-m-d",strtotime($filedata[13])): NULL),
        'purchaser'            => ($filedata[2] != 'Interstar' 'ShastaBeam'),
        'is_active'            => $filedata[11],
        'customer_id'        => 0,
    );
    $lastInsertID $this->simsModel->insert($data);
    echo $this->simsModel->lastQuery '<br>';
    //$lastInsertID = $insert->insertID();

    // Add Equipment History Record
    $logdata = [
        'card_id'        => $lastInsertID,
        'user_id'          => 0,
        'customer_id'    => 0,
        'date_changed'  => date("Y-m-d H:i:s"),
        'action'          => 'SIM Card imported from Access.',
    ];
    $this->simslogmodel->insert($logdata);
    echo $this->simslogmodel->lastQuery '<br>';
}
$i++; 


Sample from the echo statements where it changes:
Code:
INSERT INTO `inventory_sims` (`vendor_id`, `carrier`, `card_num`, `mdn`, `macid`, `invoicenum`, `cost`, `location`, `notes`, `badcard`, `date_purchased`, `date_activated`, `date_deactivated`, `purchaser`, `is_active`, `customer_id`) VALUES ('4', 'AT&T', '89014103272867252393', '5308067249', '6003474ECA0C', 'N100-OY-2063951', '0', 'lo-p3zd82dgjj', '', '0', '2016-01-01', '2021-03-22', NULL, 'Interstar', '1', '0')
INSERT INTO `inventory_sims_history` (`card_id`, `user_id`, `customer_id`, `date_changed`, `action`) VALUES ('881', '0', '0', '2021-10-20 09:46:08', 'SIM Card imported from Access.')
INSERT INTO `inventory_sims` (`vendor_id`, `carrier`, `card_num`, `mdn`, `macid`, `invoicenum`, `cost`, `location`, `notes`, `badcard`, `date_purchased`, `date_activated`, `date_deactivated`, `purchaser`, `is_active`, `customer_id`) VALUES ('4', 'AT&T', '89014103272867252559', '5308067236', '6003474EC419', 'N100-OY-2063951', '0', 'lo-p3zd82dgjj', '', '0', '2016-01-01', '2021-03-22', NULL, 'Interstar', '1', '0')
INSERT INTO `inventory_sims_history` (`card_id`, `user_id`, `customer_id`, `date_changed`, `action`) VALUES ('882', '0', '0', '2021-10-20 09:46:08', 'SIM Card imported from Access.')
SELECT 1 FROM `inventory_sims` WHERE `card_num` = '8901260191742830170F' LIMIT 1
INSERT INTO `inventory_sims_history` (`card_id`, `user_id`, `customer_id`, `date_changed`, `action`) VALUES ('', '0', '0', '2021-10-20 09:46:08', 'SIM Card imported from Access.')
SELECT 1 FROM `inventory_sims` WHERE `card_num` = '8901260235704862182F' LIMIT 1
INSERT INTO `inventory_sims_history` (`card_id`, `user_id`, `customer_id`, `date_changed`, `action`) VALUES ('', '0', '0', '2021-10-20 09:46:08', 'SIM Card imported from Access.')
SELECT 1 FROM `inventory_sims` WHERE `card_num` = '8901260191742832499F' LIMIT 1
Hopefully someone out there has a clue as to what is going on. It makes absolutely no sense!

TIA
Marc
Reply


Messages In This Thread
Looped Insert changes to Select - by SoccerGuy3 - 10-20-2021, 10:02 AM
RE: Looped Insert changes to Select - by ikesela - 10-20-2021, 10:00 PM
RE: Looped Insert changes to Select - by php_rocs - 10-21-2021, 11:08 AM
RE: Looped Insert changes to Select - by Acuru - 10-21-2021, 11:45 AM
RE: Looped Insert changes to Select - by php_rocs - 10-21-2021, 12:01 PM
RE: Looped Insert changes to Select - by InsiteFX - 10-22-2021, 12:56 AM



Theme © iAndrew 2016 - Forum software by © MyBB