I have the following code (more or less) for importing anywhere from 500,000 to 4,000,000 lines:
$sSql = "Insert into 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 properly 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 you can see, I commit every 100 lines, and I even added a bit of sleep. I used to execute commit only once every 25,000 lines, and I did not use sleep. However, at some point I found that I had no records. I started playing with these settings (sleep and row count). Thus, I reduced the number of missing entries from 50,000 to 100. But I still have not enough entries! Where are they going? I know that SQL is fine, because I get errors right away when something is wrong.
I thought I could lay out a lot of attachments during a transaction? Can a beginTransaction problem be a problem?
UPDATE:
The reward is over, and I had to reward it. Thank you all for your answers. Or advice in fact, since none of you answered my question. I did not ask for a workaround, although your suggestions are much appreciated. The answer to the award was awarded for receiving it, because it turned out to be closest to my answer. Unfortunately, this did not work.
Right now I'm using CSV import, which works fine, but if anyone has any other tips to fix this problem, let me know. Since I prefer to use my original method.