Interview question
What is the difference between bindParam() and bindValue() in PDO? PDO में bindParam() और bindValue() में क्या अंतर है?
Answer
| Aspect | bindParam() | bindValue() |
|---|---|---|
| Binding type | By reference | By value |
| When value is read | At execute() time | Immediately when called |
| Use case | Variable may change before execute | Value is fixed at bind time |
$stmt = $pdo->prepare('SELECT * FROM users WHERE id = :id');
$id = 5;
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
$id = 10;
$stmt->execute();
// Uses 10, because bindParam reads at execute time| पहलू | bindParam() | bindValue() |
|---|---|---|
| Binding type | Reference द्वारा | Value द्वारा |
| Value कब पढ़ी जाती है | execute() के समय | Call होते ही तुरंत |
$stmt = $pdo->prepare('SELECT * FROM users WHERE id = :id');
$id = 5;
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
$id = 10;
$stmt->execute();
// 10 use होगा, क्योंकि bindParam execute time पर पढ़ता हैWas this answer clear?