Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 30th, 2012  |  syntax: None  |  size: 0.53 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. What's the difference between PDOStatement->bindParam() and PDOStatement->bindValue()?
  2. $sex = 'male';
  3. $s = $dbh->prepare('SELECT name FROM students WHERE sex = :sex');
  4. $s->bindParam(':sex', $sex); // use bindParam to bind the variable
  5. $sex = 'female';
  6. $s->execute(); // executed with WHERE sex = 'female'
  7.        
  8. $sex = 'male';
  9. $s = $dbh->prepare('SELECT name FROM students WHERE sex = :sex');
  10. $s->bindValue(':sex', $sex); // use bindValue to bind the variable's value
  11. $sex = 'female';
  12. $s->execute(); // executed with WHERE sex = 'male'