Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lamngockhuong/ebd6b8060151edecc834d7c62d12d330 to your computer and use it in GitHub Desktop.
Save lamngockhuong/ebd6b8060151edecc834d7c62d12d330 to your computer and use it in GitHub Desktop.
[PDO: Sự khác nhau giữa bindValue và bindParam (Xem ví dụ để thấy sự khác nhau)] #php
$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'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment