类型定义字符串与绑定变量的数量不匹配 [英] type definition string doesn't match number of bind variables

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

问题描述

我使用为所有项目构建的动态数据库类.刚开始有一个新课程,这堂课给我打了个cup头.这是我的代码,而不是细节.但是我通过最少的代码重新创建了错误.

I use a dynamic database class I constructed for all my projects. Just started with a new one, and the class is giving me a hiccup. This is my code, not the details. But I recreated the error through minimal code.

function vref($arr) {
  if (strnatcmp(phpversion(),'5.3') >= 0) {//Reference is required for PHP 5.3+
    $refs = array();
    foreach($arr as $key => $value) $refs[$key] = &$arr[$key];
    return $refs;
  }
  return $arr;
}

$bind = 's,i,i,i,i, i,s,s,s,s, i,s,s';
$reward = ( $data['reward'] ) ? $data['reward'] : '0';
$special = '0';
$icon = '0';
$mastery = ( @$data['mastery'] ) ? 'Yes' : 'No';
$added = time();
settype($added, 'string')
$arr = array(
        $bind,
        $data['name'],
        intval($data['cost']),
        intval($data['per']),
        intval($data['serv']),
        intval($data['earns']),
        intval($data['cp']),
        $data['cookTime'],
        $reward,
        $special,
        $icon,
        intval($data['type']),
        $mastery,
        $added );

$db = new mysqli(...);
$stmt = $db2->prepare('INSERT INTO recipe2 (
     `name`,cost,perserv,servings,earns,
     cp,cooktime,`unlock`,special,icon,
     `type`,options,added) 
   VALUES (?,?,?,?,?, ?,?,?,?,?, ?,?,?) ');
call_user_func_array( array( $stmt, 'bind_param' ), vref($arr) );

// var_dump($arr)
array(14) {
[0]=> string(25) "s,i,i,i,i,i,s,s,s,s,i,s,s"
[1]=> string(18) "Bacon Cheeseburger"
[2]=> int(15)
[3]=> int(4)
[4]=> int(13)
[5]=> int(56)
[6]=> int(6)
[7]=> string(2) "5m"
[8]=> string(1) "0"
[9]=> string(1) "0"
[10]=>int(0)
[11]=>int(0)
[12]=>string(2) "No"
[13]=>string(10) "1325300795"
}

// Database Column listing
name        varchar(255)            
cost        int(10)
perserv     int(5)
servings    int(10)
earns       int(10)
cp      int(10)
cooktime    varchar(11)
unlock      varchar(255)
special     varchar(255)
icon        varchar(255)
type        int(5)
options     varchar(255)
added       varchar(12)

错误:警告:mysqli_stmt :: bind_param():类型定义字符串中的元素数量与绑定变量的数量不匹配

在有人简单地说之前,先计算一下您的变量.我有.现在大概超过50次.可不是闹着玩的.一个小时前,我开始使用变量,而不是直接输入数据. vref()只是将数组中的所有项目作为参考变量传递.从那以后,我了解到不应轻易掉以轻心.嘿.但是我仍然无法弄清这一点,而且令人沮丧.

And before anyone just simply says, count your variables. I have. Probably over 50 times now. No joke. Before an hour ago, I started using the variables, instead of direct data being put into that. vref() simply passes all the items in the array as reference variables. I have since learned that references are not to be taken lightly. Heh. But I still can't figure this out, and its frusterating.

我有13栏. 14个参数传递到bind_param().

I have 13 columns. 14 parameters being passed into bind_param().

推荐答案

简单错误.我讨厌那个. 不是我的功劳.

Simple mistake... Ugh. I hate that. Not my credit.

$bind = 'siiiiissssiss'; // No commas

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

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