我在使用mysqli_stmt :: bind_param()时遇到问题。有人能帮我吗? 警告:mysqli_stmt :: bind_param()[mysqli-stmt.bind-param]:类型定义字符串中的元素数与绑定变量数不匹配...
我是php的初学者。感谢
public function init($cards,$table,$seats)
{
$operation = $this->operation($table, $seats);
return $this->insertCards($cards,$operation,count($cards));
}
public function operation($table, $seats)
{
$operation = "insert into ".$table."(";
$values = "(";
for($i = 0; $i<count($seats);$i++)
{
$operation .= " cardsSeat".$seats[$i].",";
$values .= "?,";
}
$values .= "?,?,?)";
$operation .= " flop, turn, river) values ".$values;
return $operation;
}
public function insertCards($cards, $operation, $x)
{
$insertCards = $this->spojenie->prepare($operation);
$refArray = array();
foreach($cards as $key => $value) $refArray[$key] = &$cards[$key];
call_user_func_array(array($insertCards, 'bind_param'), $refArray);
$insertCards->execute();
return true;
}
答案 0 :(得分:2)
解决
公共功能insertCards($ cards,$ operation,$ x) {
$types = "";
foreach($cards as $value)
$types .= "s";
$cards = array_merge(array($types),$cards);
$insertCards = $this->spojenie->prepare($operation);
$refArray = array();
foreach($cards as $key => $value) $refArray[$key] = &$cards[$key];
call_user_func_array(array($insertCards, 'bind_param'), $refArray);
$insertCards->execute();
return true;
}