par
moogli » 21 févr. 2014, 12:46
salut,
1/ ton code n'est pas complet donc on ne peux pas savoir ce que tu fait exactement (vu les symptôme l'update est après la fermeture du while)
2/ tu peux simplifier ton code, autant en "performance", lisibilité que fonctionnellement (que fait tu si la ligne fait plus de 4096 octect ?).
Exemple avec PDO (parce que mysql est "dépréciée" et sera supprimée il est temps de voir autre chose, tu peux aussi utiliser mysqli qui est plus proche de mysql coté syntaxe).
<?php
$cnx = new PDO('mysql:host=localhost;dbname=labase', 'user', 'passwd');
$csvTab = file($_FILES["fichier"]["tmp_name"]);
$stmt = $cnx->prepare('UPDATE client SET code_client = :cdeCli, marque = :marque, sda = :sda,
numero_transfert = :numTransfert, type = :type, suivi_par = :suivis, raison_sociale = :raisonSocial,
complement = :complement, adresse1 = :adress1, adresse2 = :adress2, adresse3 = :adress3, code_postal = :cp,
ville = :ville, pays = :pays, civilite = :civilite, nom = :nom, prenom = :prenom, tel_fixe =:tfixe,
tel_portable = :tportable, fax = :fax, mail = :mail, mail_bis = :mailb, date_naissance = :dtnaiss,
login = :log, password = :passwd WHERE id_vp = :idvp');
foreach ($csvTab as $csvLine) {
$data = str_getcsv($csvLine,';');
$stmt->bindValue(':cdeCli',$data[0]);
$stmt->bindValue(':marque',$data[1]);
$stmt->bindValue(':sda',$data[2]);
$stmt->bindValue(':numTransfert',$data[3]);
$stmt->bindValue(':type',$data[4]);
$stmt->bindValue(':suivis',$data[5]);
$stmt->bindValue(':raisonSocial',$data[6]);
$stmt->bindValue(':complement',$data[7]);
$stmt->bindValue(':adress1',$data[8]);
$stmt->bindValue(':adress2',$data[9]);
$stmt->bindValue(':adress3',$data[10]);
$stmt->bindValue(':cp',$data[11]);
$stmt->bindValue(':ville',$data[12]);
$stmt->bindValue(':pays',$data[13]);
$stmt->bindValue(':civilite',$data[14]);
$stmt->bindValue(':nom',$data[15]);
$stmt->bindValue(':prenom',$data[16]);
$stmt->bindValue(':tfixe',$data[17]);
$stmt->bindValue(':tportable',$data[18]);
$stmt->bindValue(':fax',$data[19]);
$stmt->bindValue(':mail',$data[20]);
$stmt->bindValue(':mailb',$data[21]);
$stmt->bindValue(':dtnaiss',$data[22]); // transformation de date je suppose ? => dateTime
$stmt->bindValue(':log',$data[23]);
$stmt->bindValue(':passwd',$data[24]);
$stmt->bindValue(':idvp',$data[25],PDO::PARAM_INT);
$stmt->execute();
// sans trop toucher aux données tu peux aussi faire un $stmt->execute($data); sans les 26 lignes qui précede
}
plus d'info sur les requêtes préparées avec pdo
http://www.php.net/manual/fr/pdo.prepar ... ements.php
pour info
- ton modèle de base est foireux, tu y gagnerais ave un modèle correct.
- "type" est un mot clef sql il ne devrait pas être utilisé comme nom de champ.
@+
salut,
1/ ton code n'est pas complet donc on ne peux pas savoir ce que tu fait exactement (vu les symptôme l'update est après la fermeture du while)
2/ tu peux simplifier ton code, autant en "performance", lisibilité que fonctionnellement (que fait tu si la ligne fait plus de 4096 octect ?).
Exemple avec PDO (parce que mysql est "dépréciée" et sera supprimée il est temps de voir autre chose, tu peux aussi utiliser mysqli qui est plus proche de mysql coté syntaxe).
[php]<?php
$cnx = new PDO('mysql:host=localhost;dbname=labase', 'user', 'passwd');
$csvTab = file($_FILES["fichier"]["tmp_name"]);
$stmt = $cnx->prepare('UPDATE client SET code_client = :cdeCli, marque = :marque, sda = :sda,
numero_transfert = :numTransfert, type = :type, suivi_par = :suivis, raison_sociale = :raisonSocial,
complement = :complement, adresse1 = :adress1, adresse2 = :adress2, adresse3 = :adress3, code_postal = :cp,
ville = :ville, pays = :pays, civilite = :civilite, nom = :nom, prenom = :prenom, tel_fixe =:tfixe,
tel_portable = :tportable, fax = :fax, mail = :mail, mail_bis = :mailb, date_naissance = :dtnaiss,
login = :log, password = :passwd WHERE id_vp = :idvp');
foreach ($csvTab as $csvLine) {
$data = str_getcsv($csvLine,';');
$stmt->bindValue(':cdeCli',$data[0]);
$stmt->bindValue(':marque',$data[1]);
$stmt->bindValue(':sda',$data[2]);
$stmt->bindValue(':numTransfert',$data[3]);
$stmt->bindValue(':type',$data[4]);
$stmt->bindValue(':suivis',$data[5]);
$stmt->bindValue(':raisonSocial',$data[6]);
$stmt->bindValue(':complement',$data[7]);
$stmt->bindValue(':adress1',$data[8]);
$stmt->bindValue(':adress2',$data[9]);
$stmt->bindValue(':adress3',$data[10]);
$stmt->bindValue(':cp',$data[11]);
$stmt->bindValue(':ville',$data[12]);
$stmt->bindValue(':pays',$data[13]);
$stmt->bindValue(':civilite',$data[14]);
$stmt->bindValue(':nom',$data[15]);
$stmt->bindValue(':prenom',$data[16]);
$stmt->bindValue(':tfixe',$data[17]);
$stmt->bindValue(':tportable',$data[18]);
$stmt->bindValue(':fax',$data[19]);
$stmt->bindValue(':mail',$data[20]);
$stmt->bindValue(':mailb',$data[21]);
$stmt->bindValue(':dtnaiss',$data[22]); // transformation de date je suppose ? => dateTime
$stmt->bindValue(':log',$data[23]);
$stmt->bindValue(':passwd',$data[24]);
$stmt->bindValue(':idvp',$data[25],PDO::PARAM_INT);
$stmt->execute();
// sans trop toucher aux données tu peux aussi faire un $stmt->execute($data); sans les 26 lignes qui précede
}[/php]
plus d'info sur les requêtes préparées avec pdo [url]http://www.php.net/manual/fr/pdo.prepared-statements.php[/url]
pour info
- ton modèle de base est foireux, tu y gagnerais ave un modèle correct.
- "type" est un mot clef sql il ne devrait pas être utilisé comme nom de champ.
@+