所以这是我第一次使用call_user_func_array,因为我最近从mysql切换,我在执行它时遇到了一些困难。我对call_user_func_array的输入的内容和格式有点困惑。
这就是我所拥有的,从一组邮件收件人开始。我查询的目的是查找未知数量的邮件收件人的电子邮件和用户ID
$messagerecipients = implode(',', $_POST['messagerecipients']);
$messagerecipients = rtrim($messagerecipients,',');
$messagerecipients = explode(',',$messagerecipients);
$params = array();
foreach ($messagerecipients as $messagerecipient) {
$params[$messagerecipient] = $messagerecipient;
}
var_dump($params);
$getuseridquery = 'SELECT users.username, users.email, users.id FROM users WHERE users.username IN(';
foreach ($params as $id) {
$getuseridquery .= '?,';
}
我的$ params看起来像
array(2) { ["joey123"]=> string(6) "joey123" ["micsmith55"]=> string(9) "micsmith55" }
这会创建:
SELECT users.username, users.email, users.id FROM users WHERE users.username IN(?,?),
对我来说看起来很完美(我不确定$ params,但查询看起来不错)
然后我准备并执行:
$getuseridstmt = $mysqli->prepare($getuseridquery);
array_unshift($newParams, str_repeat('s', count($params)));
print count($Params);// this equals '2'
print count($newParams); //this equals '3'
var_dump($newParams);
call_user_func_array(array($getuseridstmt, 'bind_param'), $newParams);
$getuseridstmt->execute();
$getuseridstmt->store_result();
$getuseridstmt->bind_result($username, $useremail, $userid);
$useridarray = array();
$emailaddressarray = array();
while ($getuseridstmt->fetch()) {
$useridarray[] = $userid;
$emailaddressarray[] = $useremail;
}
但是我无法从这些数组中得到任何东西。我几乎不知道如何调试它,这肯定是问题的一部分。
真诚地感谢您的帮助。非常感谢。