0

my question is simple - I want to have variable SELECT but this doesnt work, probably because of param type casting. How can I make it work?

$statement = $pdo->prepare("SELECT :select FROM hp_data");
$statement->bindValue(":select", $_GET['polozky']);
$statement->execute();
$rows = $statement->fetchAll();

Or is it safe to simply put SELECT into query? I guess it is not.

$pdo->prepare("SELECT {$_GET['polozky']} FROM hp_data")

Thanks in advance.

Petr Beneš
  • 303
  • 3
  • 15

0 Answers0