//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
txtfile
AfterrunningPHPcode
AsingleINSERT...VALUESstatementcanaddmultiplerecordstoatableifyousupplymultiplelistsofvalues.Todothis,providealistofvaluesinparenthesesforeachrecordandseparatethelistswithcommas.
Forexample:
"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 declaration shown creates records in the info table, assigning the listed values to the COD, NOME, CARACT, END, CPF
columns of each record. The id (if any) column is not listed explicitly, so MySQL assigns a string value to that column in each record.
A multi-line INSERT statement is logically equivalent to a set of individual single-line declarations. However, multi-line declaration is more efficient because the server can process all lines at once rather than in separate operations. When you have many records to add, multi-line declarations provide better performance and reduce server load.