Avatar ·

What is the difference between bindParam and bindValue in PDO? Detailed explanation with examples

Hello everyone! I started learning PDO and came across two methods: `bindParam()` and `bindValue()`. The documentation says they are both used to bind parameters to a prepared statement, but I can't understand the difference between them. I have this code: ```php $stmt = $pdo->prepare('SELECT * FROM users WHERE id = :id'); $id = 5; $stmt->bindParam(':id', $id); $stmt->execute(); ``` If I replace `bindParam` with `bindValue`, the result will be the same. But I heard there is some important difference related to passing by reference. Can you explain with simple examples when to use `bindParam` and when to use `bindValue`? And why do two methods exist if they do the same thing? I am especially interested in the situation with loops. I saw code where `bindPar` is called in a loop