Pregunta

Would this code work? If not, what are my options?

$stmt = $db->prepare("SELECT * FROM table WHERE ? = ? AND ? = ?");
$stmt->execute( array( $column1 => $value1, $column2 => $value2 ) );
¿Fue útil?

Solución

No, you need to supply the table field names, the values can be substituted.

$stmt = $db->prepare("SELECT * FROM table WHERE column1 = :value1 AND column2= :value2");
$stmt->execute( array( ':value1' => $value1, ':value2' => $value2 ) );

http://www.php.net/manual/en/pdo.prepare.php

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top