mysqli_stmt :: bind_param()类型定义字符串中的元素数与数字不匹配 [英] mysqli_stmt::bind_param()Number of elements in type definition string doesn't match number

查看:372
本文介绍了mysqli_stmt :: bind_param()类型定义字符串中的元素数与数字不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用mysqli_stmt::bind_param()时遇到问题.

I have a problem with using mysqli_stmt::bind_param().

警告:mysqli_stmt :: bind_param()[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;
}

推荐答案

已解决

  • 字符串类型("sss ...");

  • 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;
}

这篇关于mysqli_stmt :: bind_param()类型定义字符串中的元素数与数字不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆