问题描述
我有以下代码行可在PHP 5.1中使用,但不适用于PHP 5.3.
I have the following line of code which worked in PHP 5.1, but isn't working in PHP 5.3.
$input = array('ss','john','programmer');
call_user_func_array(array($mysqli_stmt, 'bind_param'), $input);
在PHP 5.3中,我收到以下警告消息:
In PHP 5.3, I get the following warning message:
我将代码更改为以下代码,并且有效:
I changed the code to the following and it worked:
$a = 'johnl';
$b = 'programmer';
$mysqli_stmt->bind_param('ss',$a,$b);
我在php文档中找到了这个
I found this in the php documentation:
所以我的问题是,如何复制call_user_func_array + bind_params的功能,以便我可以在运行时动态绑定变量?
So my question is, how do I replicate the functionality of the call_user_func_array + bind_params such that i can dynamically bind variables at run time?
推荐答案
我在 fabio于br3年前在Kidopi dot com dot 上,在mysqli_stmt::bind_param()
的PHP手册页上(略作修改):
I found the answer to my problem in a user note by fabio at kidopi dot com dot br3 years ago on the PHP manual page of mysqli_stmt::bind_param()
(slightly modified):
原因是5.3要求将数组值用作引用,而5.2则需要使用实数值(也可以使用引用).因此,我创建了一个辅助帮助程序功能来帮助我解决这个问题:
The cause is that 5.3 requires array values as reference while 5.2 worked with real values (but also with references). So I created a secondary helper function to help me with this:
function refValues($arr)
{
$refs = array();
foreach ($arr as $key => $value)
{
$refs[$key] = &$arr[$key];
}
return $refs;
}
并从以下位置更改了我以前的功能:
and changed my previous function from:
call_user_func_array(array($this->stmt, "bind_param"), $this->values);
收件人:
call_user_func_array(array($this->stmt, "bind_param"), refValues($this->values));
这样,我的数据库功能就可以在PHP 5.2/5.3服务器中正常工作.
This way my db functions keep working in PHP 5.2/5.3 servers.
这篇关于php5.3-mysqli_stmt:bind_params带有call_user_func_array警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!