Skip to content

Instantly share code, notes, and snippets.

@proclnas
Created June 2, 2018 17:42
Show Gist options
  • Save proclnas/1c1ca64c14ae31bcbac3d42971986ca5 to your computer and use it in GitHub Desktop.
Save proclnas/1c1ca64c14ae31bcbac3d42971986ca5 to your computer and use it in GitHub Desktop.
<?php
// Forma procedural
function getPdoHandle() { /* ... */ }
function fetchAll($handle, $tabela) {
// Whitelist simples de tabelas permitidas
$tabelasPermitidas = ['produtos', 'lojas', 'marcas'];
if (!in_array($tabela, $tabelasPermitidas)) return false;
$query = sprintf('SELECT * FROM %s', $tabela);
$stm = $handle->prepare($query);
$stm->execute();
return $stm->fetchAll(PDO::FETCH_ASSOC);
}
$pdo = getPdoHandle();
$tabelas = ['produtos', 'lojas', 'marcas'];
foreach ($tabelas as $tabela) {
$resultados = fetchAll($pdo, $tabela);
if (!$resultados) continue;
// Lógica aqui
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment