本文介紹了PDO 通過引用通知?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
這個:
$stmt = $dbh->prepare("SELECT thing FROM table WHERE color = :color");
$stmt->bindParam(':color', $someClass->getColor());
$stmt->execute();
產(chǎn)生這個:
運行時通知
只應傳遞變量參考
Runtime notice
Only variables should be passed by reference
雖然它仍然執(zhí)行.
這個:
$stmt = $dbh->prepare("SELECT thing FROM table WHERE color = :color");
$tempColor = $someClass->getColor();
$stmt->bindParam(':color',$tempColor);
$stmt->execute();
毫無怨言地運行.
我不明白其中的區(qū)別?
推薦答案
bindParam 的第二個參數(shù)是一個變量 參考.由于函數(shù)返回不能被引用,它不能嚴格滿足bindParam參數(shù)的需求(PHP會配合你,這里只會發(fā)出警告).
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).
為了更好地理解,這里有一個例子:這段代碼將產(chǎn)生與你的第二個例子相同的結果:
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();
這在函數(shù)返回的情況下是不可能的.
That won't be possible with a function return.
這篇關于PDO 通過引用通知?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!