Considering I'm building a form and posting the data to PHP, a typical insert query for me goes like this:
$sql = "INSERT INTO news
(title, body)
VALUES (?, ?)";
$stmt = $db->prepare($sql);
$stmt->execute(array($_POST["title"], $_POST["body"]));
$stmt->closeCursor();
This looks fine for a small query, and it is my understanding that this keeps me safe from the likes of SQL injection and whatnot.
But what if I need to work with a pretty big form? Something like...
$sql = "INSERT INTO ficha_item
(titulo, tipo_produto, quantidade_peso, unidade_de_venda,
unidades_por_caixa, caixas_piso, pisos_palete, tipo_de_palete,
unidades_palete, caixas_palete, uni_diametro, uni_largura,
uni_profundidade, uni_altura, uni_peso_bruto_unidade, caixa_largura,
caixa_profundidade, caixa_altura, altura_palete, volume_unidade,
peso_caixa, peso_palete)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
I think it becomes tedious counting all these question marks. Is there a cleaner way to do this with PDO?