fomalhaut
Member
- Messages
- 107
- Reaction score
- 0
- Points
- 16
Hello all.
The table is very simple: 1 field type integer and 2 fields type char:
I've a file containing mysql data save, each line is a row, each field separate by the caracter '|'.
I wanna insert data from file, only if the couple "repertoire" + "compl_name" does not already exist.
here is the php: ($lgn is the line beeing read from the file)
But the problem is that when the table row exists that was created by the application (sql insert from another php script), the script above treats it as not the same, and it inserts it. And after that, the 2 rows seems strictely identical through phpMyAdmin.
When the table row doesn't exists, the script inserts it, of course.
When the table row exists that was inserted by the above script itself in a previous run, it doesn't insert it, viewing it's the same.
Thank you for guide me on this problem. I've searched in several ways, without understand anything on that !
The table is very simple: 1 field type integer and 2 fields type char:
Code:
noCROA int(6) unsigned not null
repertoire char(25) not null
compl_name char(120) not null
Code:
2|CROA/Test|fichier_test.jpg
here is the php: ($lgn is the line beeing read from the file)
PHP:
case "jyc_astronomie.fichiers_compl":
// attention la liste des noms de variable ci-dessous doit être en phase avec le script d'insertion correspondant
list($noCROAAIns, $repertoireComplAIns, $complNameAIns) = explode("|", $lgn);
// on regarde si le duo répertoire/complName existe
$How = "SELECT count(*) FROM jyc_astronomie.fichiers_compl WHERE repertoire ='".$repertoireComplAIns."' AND compl_name = '".$complNameAIns."'";
if ($res = $dbh->query($How)) {
//si le duo répertoire - complName n'existe pas, on crée
if ($res->fetchColumn() <= 0) {
$insFichiersCompl->execute();
$enregIns++;
}
else {
$Tmsg = 'Le fichier complément <b>'.$repertoireComplAIns.$complNameAIns.'</b> existe déjà, associé au CROA n° <b>'.$noCROAAIns.' </b>: non remplacé<br />';
echo $Tmsg;
}
}
break;
When the table row doesn't exists, the script inserts it, of course.
When the table row exists that was inserted by the above script itself in a previous run, it doesn't insert it, viewing it's the same.
Thank you for guide me on this problem. I've searched in several ways, without understand anything on that !