PDO通过参考通知吗? [英] PDO pass by reference notice?
本文介绍了PDO通过参考通知吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此:
$stmt = $dbh->prepare("SELECT thing FROM table WHERE color = :color");
$stmt->bindParam(':color', $someClass->getColor());
$stmt->execute();
得出这样的结果:
运行时通知
仅应传递变量 参考
Runtime notice
Only variables should be passed by reference
尽管它仍然执行.
此:
$stmt = $dbh->prepare("SELECT thing FROM table WHERE color = :color");
$tempColor = $someClass->getColor();
$stmt->bindParam(':color',$tempColor);
$stmt->execute();
运行无投诉.
我不明白区别吗?
推荐答案
bindParam的第二个参数是变量参考.由于无法引用函数返回,因此它不能严格满足bindParam参数的需求(尽管PHP可以与您一起使用,并且只会在此处发出警告).
The second parameter of bindParam is a variable reference. Since a function return cannot be referenced, it fails to strictly meet the needs of the bindParam parameter (PHP will work with you though and will only issue a warning here).
为获得更好的主意,请参见以下示例:此代码将产生与您的第二个示例相同的结果:
To get a better idea, here's and example: this code will produce the same results as your second example:
$stmt = $dbh->prepare("SELECT thing FROM table WHERE color = :color");
$tempColor = NULL; // assigned here
$stmt->bindParam(':color',$tempColor);
$tempColor = $someClass->getColor(); // but reassigned here
$stmt->execute();
使用函数返回将无法实现.
That won't be possible with a function return.
这篇关于PDO通过参考通知吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文