Understanding bindParam

Hello all,

If we do:

$hello = 'insert something';
$stmt = $db->prepare("INSERT INTO testCase (something) VALUES (?)");
$stmt->bindParam(1, $hello, PDO::PARAM_STR, 255);

No issues. All good.

HOWEVER, if we do:

$stmt = $db->prepare("INSERT INTO testCase (something) VALUES (?)");
$stmt->bindParam(1, 'insert something', PDO::PARAM_STR, 255);

We get: Cannot pass parameter 2 by reference.

Can anyone explain me what does pass by reference means in simpler terms please? (:

Your parameter 2 is string constant rather than variable (since you cannot refer to “insert something” by using a variable like $str or similar).

PDO documentation says that parameter 2 is expected to be a variable passed by reference (it says mixed &$variable, & operator indicates how the variable is passed), however you passed a string constant rather than a variable raising an error.
Example you provided explains everything in a nutshell - stick the content to the variable, pass the variable.
More on references: http://www.php.net/manual/en/language.references.php