code_junkie

Can PHP PDO Statements accept the table name as parameter?

Nov 11th, 2011
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. $stmt = $dbh->prepare('SELECT * FROM :table WHERE 1');
  2. if ($stmt->execute(array(':table' => 'users'))) {
  3. var_dump($stmt->fetchAll());
  4. }
  5.  
  6. $sql = "SELECT * FROM $table WHERE 1"
  7.  
  8. function buildQuery( $get_var )
  9. {
  10. switch($get_var)
  11. {
  12. case 1:
  13. $tbl = 'users';
  14. break;
  15. }
  16.  
  17. $sql = "SELECT * FROM $tbl";
  18. }
Add Comment
Please, Sign In to add comment