D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
var
/
www
/
html
/
crsys_ant
/
adm
/
Filename :
atualiza_indic_produto.php
back
Copy
<?php require 'vendor/autoload.php'; define('HOST', 'localhost:3308'); define('USER', 'root'); define('PASS', ''); define('DBNAME', 'crsys'); try { $pdo = new PDO("mysql:host=" . HOST . ";dbname=" . DBNAME . ";charset=utf8", USER, PASS); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { die(json_encode(["status" => "erro", "mensagem" => "Erro na conexão: " . $e->getMessage()])); } use PhpOffice\PhpSpreadsheet\IOFactory; // Caminho local da planilha $arquivo = 'C:/wamp64/www/crsys/adm/tblprodutosaida.xlsx'; if (!file_exists($arquivo)) { die("Arquivo não encontrado: $arquivo"); } $spreadsheet = IOFactory::load($arquivo); $sheet = $spreadsheet->getActiveSheet(); $rows = $sheet->toArray(null, true, true, true); // lê como array associativo foreach ($rows as $index => $row) { if ($index === 1) continue; // pula cabeçalho $codigo = $row['A']; $grupo = $row['E']; $sem_tampo = $row['G']; $aca_lat_sup = $row['H']; $aca_lat_inf = $row['I']; $aca_lat_esq = $row['J']; $aca_lat_dir = $row['K']; $saia_lat_sup = $row['L']; $saia_lat_inf = $row['M']; $saia_lat_esq = $row['N']; $saia_lat_dir = $row['O']; $fro_lat_sup = $row['P']; $fro_lat_inf = $row['Q']; $fro_lat_esq = $row['R']; $fro_lat_dir = $row['S']; // Atualiza a tabela produtos onde id = codigo $sql = "UPDATE gre_produtos SET grupo = :grupo, sem_tampo = :sem_tampo, aca_lat_sup = :aca_lat_sup, aca_lat_inf = :aca_lat_inf, aca_lat_esq = :aca_lat_esq, aca_lat_dir = :aca_lat_dir, saia_lat_sup = :saia_lat_sup, saia_lat_inf = :saia_lat_inf, saia_lat_esq = :saia_lat_esq, saia_lat_dir = :saia_lat_dir, fro_lat_sup = :fro_lat_sup, fro_lat_inf = :fro_lat_inf, fro_lat_esq = :fro_lat_esq, fro_lat_dir = :fro_lat_dir WHERE id = :codigo"; try { $stmt = $pdo->prepare($sql); $stmt->execute([ ':grupo' => $grupo, ':sem_tampo' => $sem_tampo, ':aca_lat_sup' => $aca_lat_sup, ':aca_lat_inf' => $aca_lat_inf, ':aca_lat_esq' => $aca_lat_esq, ':aca_lat_dir' => $aca_lat_dir, ':saia_lat_sup' => $saia_lat_sup, ':saia_lat_inf' => $saia_lat_inf, ':saia_lat_esq' => $saia_lat_esq, ':saia_lat_dir' => $saia_lat_dir, ':fro_lat_sup' => $fro_lat_sup, ':fro_lat_inf' => $fro_lat_inf, ':fro_lat_esq' => $fro_lat_esq, ':fro_lat_dir' => $fro_lat_dir, ':codigo' => $codigo ]); } catch (PDOException $e) { echo "Erro ao atualizar código $codigo: " . $e->getMessage() . "<br>"; } } echo "Atualização concluída com sucesso."; ?> ?>