php - Records disappearing in PDO mssql transaction loop -
i have following code (more or less) import anywhere 500.000 4.000.000 rows:
$ssql = "insert table (a,b,c) values(?,?,?)" $osqlstmnt = $pdo->prepare($ssql); $osqlstmnt->setattribute(pdo::sqlsrv_attr_encoding, pdo::sqlsrv_encoding_system); if (!$osqlstmnt) { echo $pdo->errorinfo(); // handle errors } $pdo->begintransaction(); $ilinecounter = 1; while (($sline = fgets ($ocsv, 8000)) !== false) { $aline = explode('|', $sline); //fgetscsv did not work if ($ilinecounter % 100 == 0) { lo("inserting row " . $ilinecounter); $pdo->commit(); sleep(0.15); $pdo->begintransaction(); } try { $osqlstmnt->execute($aline); $isuccesulinserts++; } catch (exception $e) { print_r($e); $ifailedinserts++; } $ilinecounter++; } $pdo->commit();
as can see, perform commit every 100 lines, , added sleep. used run commit once every 25.000 lines, , did not use sleep. however, @ 1 point, discovered missing records. started playing these settings (sleep , number of rows). way reduced number of missing records 50.000 100. i'm still missing records! going? know sql ok, because receive errors when somethings wrong there.
i thought stack lot of inserts during transaction? calling begintransaction problem?
update:
the bounty ended , had award it. thank answers. or tips actually, none of answered question. not asking workaround, although suggestions appreciated. answer bounty awarded received because came closest answering question. unfortunately did not work.
for i'm using csv bulk import, works fine, if has other tips fixing issue, please let me know. prefer using original method.
have considered using sprocs instead of insert statements? writing number of records sequentially- 1 @ time- kindof waste of time / energy.. it's not fast should be.
are sure can't use bulk insert or xml instead insert multiple rows @ time?
Comments
Post a Comment