I have the following line of code that performs the import of the txt file.
<?php
function Inserir($itens, Pdo $pdo){
$sts = $pdo->prepare("INSERT INTO dados(loja, cod_prod, cod_acesso, desc_prod, estoq_disp, data, estoq_validade) VALUES(?,?,?,?,?,?,?);");
$sts->bindValue(1, $itens[0], PDO::PARAM_STR);
$sts->bindValue(2, $itens[1], PDO::PARAM_STR);
$sts->bindValue(3, $itens[2], PDO::PARAM_STR);
$sts->bindValue(4, $itens[3], PDO::PARAM_STR);
$sts->bindValue(5, $itens[4], PDO::PARAM_STR);
$sts->bindValue(6, $itens[5], PDO::PARAM_STR);
$sts->bindValue(7, $itens[6], PDO::PARAM_STR);
$sts->execute();
$sts->closeCursor();
$sts = NULL;
}
if (!empty($_FILES['arquivo']))
{
$Pdo = new PDO("mysql:host=localhost;dbname=vencimento", "root", "");
$file = fopen($_FILES['arquivo']['tmp_name'], 'r');
while (!feof($file)){
$linha = fgets($file);
$itens = explode(';', $linha);
Inserir($itens, $Pdo);
}
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Arquivo</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" enctype="multipart/form-data" method="post">
<input type="file" name="arquivo" id="arquivo">
<input type="submit" name="enviar" value="Enviar">
</form>
</body>
</html>
I need at the time of inserting in the database the lines of the file that are exactly the same as those already existing inside the database, it ignores that line and only inserts those that are not equal.