I have a .csv
file with two columns, one with id
and another with status
of my product, I need to change these products to status
0 (zero), that is, to inactivate them , but the quantity of products exceeds 400 records, how can I read this file and perform a batch update?
I could not make anything that worked.
I made a code following a tip, it looked like this:
// ARQUIVO NO SERVIDOR
$arquivo = 'c:\inativos.txt';
// ARRAY QUE RECEBERÁ DADOS IMPORTADOS
$arquivoArr = array();
// SOMENTE LEITURA
$arq = fopen($arquivo, 'r');
$i = 0;
while(!feof($arq)){
$conteudo = fgets($arq);
$arquivoArr[$i] = $conteudo;
$i++;
}
// CONEXÃO COM BD
require_once('Connections/conexao.php');
foreach($arquivoArr as $linha):
mysql_select_db($database_conexao, $conexao);
$sqlUp = "UPDATE produtos SET status = 0 WHERE id_produto = $linha";
$fim = mysql_query($sqlUp,$conexao) or die ( "Erro alterando dados no Banco de Dados" );
endforeach;
But giving echo
in variable $sqlUp
returns me this: UPDATE produtos SET status = 0 WHERE id_produto = ��1