Insert dinâmico com PDO.
public function read($tabela, $where = null, $limit = null, $offset = null, $orderby = null){
$where = ($where != null ? "WHERE {$this->AntiSQL($where)}" : "");
$limit = ($limit != null ? "LIMIT {$this->AntiSQL($limit)}" : "");
$offset = ($offset != null ? "OFFSET {$this->AntiSQL($offset)}" : "");
$orderby = ($orderby != null ? "ORDER BY {$this->AntiSQL($orderby)}" : "");
$query = "SELECT * FROM {$tabela} {$where} {$orderby} {$limit} {$offset}";
#echo $query."<br />";
$q = $this->_db->query($query);
if ($q){
$q->setFetchMode(PDO::FETCH_ASSOC);
return $q->fetchAll();
} else {
return false;
}
}
Alguém pode me dá uma luz de como separar o WHERE, LIMIT, OFFSET e ORDERBY de forma que sejam enviados em parametros para o $pdo->exec?
Desde já, grato. :v
Discussão (8)
Carregando comentários...