MySQLi准备好的语句抱怨“只能通过引用传递变量". [英] MySQLi prepared statement complains that "only variables should be passed by reference"

查看:74
本文介绍了MySQLi准备好的语句抱怨“只能通过引用传递变量".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码:

$stmt->bind_param("s", md5($input['user'] . $config['salt']));

PHP错误消息:

仅变量应通过引用传递

我一直在从事这个项目,但现在被困住了.我是PHP新手.该怎么办?

解决方案

感谢使用MySQLi准备好的语句!他们很痛苦,但这是值得的.

bind_param 通过引用获取值.通过查看您传递的变量并直接指向内部对象来实现此目的.

在您的调用中,您将返回函数调用的字符串结果-在这种情况下为md5.因为没有涉及任何变量,所以没有指向的内脏.因此,PHP抱怨无法通过引用传递数据.

您需要将函数调用的结果粘贴到变量中,然后将该变量传递到绑定中.

大容量警告!md5不再是 个安全哈希,因此应 not 用于存储密码.如果有机会,您应该更新为更好的哈希格式,例如 bcrypt,PBKDF2,scrypt等. /p>

Code:

$stmt->bind_param("s", md5($input['user'] . $config['salt']));

PHP Error Message:

Only variables should be passed by reference

I've been working on this project but I am stuck now. I am new to PHP. What to do?

解决方案

Thanks for using MySQLi prepared statements! They're a pain, but it's worth it.

bind_param takes values by reference. It does this by looking at the variable you're passing and pointing at the innards directly.

In your call, you're returning the string result of a function call - md5 in this case. Because there's no variable involved, there are no innards to point to. PHP is whining about not being able to pass the data by reference as a result.

You will need to stick the result of the function call into a variable, then pass that variable into the bind instead.

BIG FAT WARNING! md5 is not a secure hash any longer, and should not be used to store passwords. When you get the chance, you should update to a better hash format, such as bcrypt, PBKDF2, scrypt, etc.

这篇关于MySQLi准备好的语句抱怨“只能通过引用传递变量".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆