[英]error Strict standards:Error Only variables should be passed by reference in C:\wamp64\www\Exercise Files\CRUD\crud-mysqli.php on line 545
On a lynda.com tutorial I am getting this error :在 lynda.com 教程中,我收到此错误:
error Strict standards:Error Only variables should be passed by reference in C:\\wamp64\\www\\Exercise Files\\CRUD\\crud-mysqli.php on line 545
error Strict Standards:Error Only variables should be used by reference in C:\\wamp64\\www\\Exercise Files\\CRUD\\crud-mysqli.php on line 545
I can't see in the code where anything is passed by reference.我在代码中看不到任何通过引用传递的内容。
I understand the @ operater is an error operator and I think this is causing the error我知道 @ 操作符是一个错误操作符,我认为这是导致错误的原因
function insert_album_sql( $album )
{
global $CRUD;
$dbh = $CRUD['dbh'];
$query = '
INSERT INTO album
( title, artist, label, released )
VALUES ( ?, ?, ?, ? )
';
$sth = $dbh->prepare($query);
if($sth) {
$sth->bind_param("ssss", @$album['title'], @$album['artist'], @$album['label'], @$album['released'] );
$sth->execute();
} else {
error("insert_album_sql: insert prepare returned no statement handle");
}
// check for errors
$err = $sth->error;
if($err) error( $err );
return($dbh->insert_id);
}
My educated guess is that line 545 is this:我有根据的猜测是第 545 行是这样的:
$sth->bind_param("ssss", @$album['title'], @$album['artist'], @$album['label'], @$album['released'] );
You have a better chance to determine it for sure than any of us, though, since any decent editor should have a way to either display line numbers or browse to a line by number.不过,您比我们任何人都有更好的机会确定它,因为任何体面的编辑器都应该有办法显示行号或逐行浏览。
From the bind_param()
manual page :从
bind_param()
手册页:
Binds variables to a prepared statement as parameters
将变量绑定到准备好的语句作为参数
That means that the function doesn't read the value.这意味着该函数不读取该值。 Instead, it keeps a reference to the original variable to read it later.
相反,它保留对原始变量的引用,以便稍后读取。 If don't provide a raw variable, it cannot work.
如果不提供原始变量,它将无法工作。
(Disclaimer: I haven't really tested whether @
in particular actually prevents bind_param()
from working because I don't know all PHP internals by heart.) (免责声明:我还没有真正测试过
@
特别是是否真的阻止了bind_param()
工作,因为我不知道所有的 PHP 内部原理。)
Solution: get rid of @
entirely.解决方案:完全摆脱
@
。 You don't want to hide error messages because coding blindly it's neither productive nor fun.您不想隐藏错误消息,因为盲目编码既没有效率也没有乐趣。
A tutorial that uses a global variable to pass the database connection to the function and abuses @
that way is not a reliable source of knowledge to begin with so it's just possible that such strict standards violation is there in the first place.使用全局变量将数据库连接传递给函数并以这种方式滥用
@
的教程一开始就不是可靠的知识来源,因此最初可能存在如此严格的标准违规行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.