lamngockhuong
11/8/2016 - 5:42 PM

PDO: Sự khác nhau giữa bindValue và bindParam (Xem ví dụ để thấy sự khác nhau)

PDO: Sự khác nhau giữa bindValue và bindParam (Xem ví dụ để thấy sự khác nhau)

  $sex = 'male';
  $s = $dbh->prepare('SELECT name FROM students WHERE sex = :sex');
  $s->bindParam(':sex', $sex); // use bindParam to bind the variable
  $sex = 'female';
  $s->execute(); // executed with WHERE sex = 'female'
or

  $sex = 'male';
  $s = $dbh->prepare('SELECT name FROM students WHERE sex = :sex');
  $s->bindValue(':sex', $sex); // use bindValue to bind the variable's value
  $sex = 'female';
  $s->execute(); // executed with WHERE sex = 'male'