mysql // ----------------------------------------------------- $handle = fopen($fileName, "r"); if (!$handle) { $mesg .= "

Impossible d'ouvrir le fichier : " . $fileName . "\n"; exit; } else { $indexBuffer = fread($handle, filesize($fileName)); } fclose($handle); // Temporary variable, used to store current query $templine = ''; // Read in entire file $lines = file($fileName); // Loop through each line $z = 0; $x = 0; // ne fonctionne pas mais pas nécessaire, pas de commit ni rollback $idPdoProd->beginTransaction(); try { foreach ($lines as $line) { // Skip it if it's a comment if (substr($line, 0, 2) == '--' || $line == '') { continue; } // Add this line to the current segment $templine .= $line; $x++; // If it has a semicolon at the end, it's the end of the query if (substr(trim($line), -1, 1) == ';') { // Perform the query if (isset($debug[1]) && $debug[1] == '1' ) { $mesg .= '
templine = ' . $templine; } // Execute query using PDO $stmt = $idPdoProd->prepare($templine); if (!$stmt->execute()) { $mesg .= 'Erreur avec la requete'; if (isset($debug[1]) && $debug[1] == '1' ) { $mesg .= '
templine = ' . $templine . ' : ' . $stmt->errorInfo()[2]; } } // Reset temp variable to empty $templine = ''; if (isset($debug[1]) && $debug[1] == '1' ) {$mesg .= '
Lignes traitées : ' . $z; } $z++; } } // Commit the transaction ne fonction pas car le egin fonctionne pas // $idPdoProd->commit(); } catch (PDOException $e) { // In case of error, rollback the transaction if ($idPdoProd->inTransaction()) { $idPdoProd->rollBack(); } $mesg .= 'Erreur PDO: ' . $e->getMessage(); if (isset($debug[1]) && $debug[1] == '1' ) { $mesg .= '
' . $e->getTraceAsString(); } } $endTime = microtime(true); // Fin du timer $elapsedTime = round($endTime - $startTime, 2); // Temps écoulé en secondes if (isset($debug[1]) && $debug[1] == '1' ) { $mesg .= 'Import ' . $export_tag . ' réalisé avec succès.
'; $mesg .= '
--> Fichier ' . $fileName . ' importé dans ' . $bddProd . ' . ' . $z . ' lignes traitées.
Temps écoulé pour import : ' . $elapsedTime . ' secondes. '; } return $mesg; } ?>