0

I would like to pass a variable directly into the select statement to identify the table, so the code recognizes SELECT * FROM us_total_Y. Is this possible with PDO? I have googled around and looked through three books but don't see an example. Would anyone know? Thank you in advance.

  $loc = 'us';
  $stmt = $pdo->prepare('SELECT * FROM :loc _total_Y');
  $stmt->execute(array('loc' => $loc));
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
CathDog
  • 1
  • 2

1 Answers1

-1

You can store the query in a variable like so

  $loc = 'us';
  $locquery = 'SELECT * FROM '.$loc.'_total_Y';
  $stmt = $pdo->prepare($locquery);
  $stmt->execute();
Richard
  • 994
  • 7
  • 26