I have a problem with using mysqli_stmt::bind_param()
.
Warning: mysqli_stmt::bind_param() [mysqli-stmt.bind-param]: Number of elements in type definition string doesn't match number of bind variables...
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;
}
Resolved
string types ("sss...");
public function 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; }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.