問題描述
請(qǐng)看下面我的代碼.我試圖將一組參數(shù)綁定到我準(zhǔn)備好的語句.我一直在網(wǎng)上環(huán)顧四周,可以看到我必須使用 call_user_func_array 但無法讓它工作.我得到的錯(cuò)誤是:第一個(gè)參數(shù)應(yīng)該是一個(gè)有效的回調(diào),給出了'Array'"我可能是錯(cuò)的,但我假設(shè)第一個(gè)參數(shù)可以是一個(gè)數(shù)組,并且這個(gè)錯(cuò)誤消息可能具有誤導(dǎo)性.我認(rèn)為問題在于我的陣列在某種程度上有問題.誰能看到我做錯(cuò)了什么?謝謝.
$type = array("s", "s");$param = array("string1","anotherstring");$stmt = $SQLConnection->prepare("INSERT INTO mytable (comp, addl) VALUES (?,?)");$params = array_merge($type, $param);call_user_func_array(array(&$stmt, 'bind_param'), $params);$SQLConnection->execute();
我不知道你為什么必須使用 call_user_func_array
,但那是另一回事了.>
在我看來,唯一可能出錯(cuò)的是您使用了對(duì)對(duì)象的引用.假設(shè)您使用的是 PHP 5.*,則沒有必要:
call_user_func_array(array($stmt, 'bind_param'), $params);
Please see below my code. I am attempting to bind an array of paramenters to my prepared statement. I've been looking around on the web and can see I have to use call_user_func_array but cannot get it to work. The error I get is: "First argument is expected to be a valid callback, 'Array' was given" I may be wrong but I'm assuming the first argument can be an an array and perhaps this error message is misleading. I think the issue is that my array is in someway at fault. Can anyone see what I am doing wrong? Thanks.
$type = array("s", "s");
$param = array("string1","anotherstring");
$stmt = $SQLConnection->prepare("INSERT INTO mytable (comp, addl) VALUES (?,?)");
$params = array_merge($type, $param);
call_user_func_array(array(&$stmt, 'bind_param'), $params);
$SQLConnection->execute();
I wouldn't know why you have to use call_user_func_array
, but that's another story.
The only thing that could be wrong in my eyes is that you are using a reference to the object. Assuming you're using PHP 5.*, that is not necessary:
call_user_func_array(array($stmt, 'bind_param'), $params);
這篇關(guān)于MySQLI 使用 call_user_func_array 綁定參數(shù)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!