Created
June 2, 2018 17:42
-
-
Save proclnas/1c1ca64c14ae31bcbac3d42971986ca5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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