//Recebe os dados do formulario
$arquivo_tmp = $_FILES['arquivo']['tmp_name'];
//ler todo o arquivo para um array
$dados = file($arquivo_tmp);
foreach($dados as $linha){
$linha = trim($linha);
$valor = explode('|', $linha);
$COD = $valor[1];
$NOME = $valor[2];
$CARACT = $valor[3];
$END = $valor[4];
$CPF = $valor[5];
//prepara os values
$result_usuario .= "('$COD','$NOME','$CARACT','$END','$CPF'),";
}
//retira a ultima virgula
$values=substr($result_usuario, 0, -1);
//a query para inserir os dados no banco
//$conn = ......
$result_usuario = "INSERT INTO info (COD, NOME, CARACT, END, CPF) VALUES $values";
$resultado_usuario = mysqli_query($conn, $result_usuario);
Bank table
txt file
After running PHP code
A single INSERT statement ... VALUES can add multiple records to a table if you provide multiple lists of values. To do this, provide a list of values in parentheses for each record and separate the lists with commas.
For example:
"INSERT INTO info (COD, NOME, CARACT, END, CPF) VALUES
('42','Carlos Paiva da Silva 2','2','Av. Alameda Santos, 2','5265482532'),('43','Carlos Paiva da Silva 3','3','Av. Alameda Santos, 3','5265482533'), etc...
The statement shown creates records in the info table, assigning to the columns COD, NOME, CARACT, END, CPF
of each record the values listed. The id column (if any) is not explicitly listed, so Mysql assigns a sequence value to that column in each record.
A multiple-line INSERT declaration is logically equivalent to a set of individual single-line statements. However, the multiple line declaration is more efficient because the server can process all lines at once instead of in separate operations. When you have many logs to add, multiple line statements provide better performance and reduce server load.
João, post at least one example of the contents of the archive
– rbz
@Rbz I updated the question with content.
– João Miguel
@Joãomiguel iae, managed to solve?
– rLinhares