简体   繁体   English

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

[英]Mysqli error with bind_param(): Number of elements in type definition string doesn't match number of bind variables

I tried what I could to solve this error without any success. 我尽力解决此错误,但没有成功。 I'm trying to dynamically build a select query with prepared statement : 我正在尝试使用准备好的语句动态构建选择查询:

I've got this code 我有这个代码

<?php
$gm = $_GET['gm']; 
$ct = $_GET['ct']; 

$query = 'SELECT * FROM fchar';

$cond = array();
$params = array();
$type = array();

if (!empty($gm)) {
$cond[] = "gm = ?";
$params[] = $gm;
$type[] = "i";
}

if (!empty($ct)) {
$cond[] = "ct = ?";
$params[] = $ct;
$type[] = "s";
}

if (count($cond)) {
$query .= ' WHERE ' . implode(' AND ', $cond);
}

if (count($params)) {
$paramok = implode(', ', $params);

}
if (count($type)) {
$typeok = implode($type);
}

$stmt = $connection->prepare($query);
$stmt->bind_param(''.$typeok.'',$paramok);

$stmt->execute();


if (!$stmt->execute()) {
echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
}
while ($stmt->fetch()) {

}
}
?>

I've got this error : 我有这个错误:

Warning: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables in C:\\xampp\\htdocs\\cebusingles\\search.php on line 42 警告:mysqli_stmt :: bind_param():类型定义字符串中的元素数量与第42行的C:\\ xampp \\ htdocs \\ cebusingles \\ search.php中的绑定变量数量不匹配

But when I echo the types and params, I've got this : 但是,当我回应类型和参数时,我得到了:

echo "<br><br>Types : ".$typeok."<br>Param: ".$paramok."<br><br>Query:   ".$query."<br><br>";
// gives :
// Types : is
// Param: 1, USA
// Query: SELECT * FROM fchar WHERE gm = ? AND ct = ?

So i have 2 types : is, and 2 param : 1, USA. 所以我有2种类型:is和2 param:1,美国。

I don't understand why it says that the number of types is not matching the number of params... Any clue ? 我不明白为什么它说类型的数量与参数的数量不匹配...任何线索? Thank you ! 谢谢 !

$stmt->bind_param(''.$typeok.'',$paramok);

Is missing what type of variabled you're trying to insert on the ? 缺少要在上插入哪种类型的变量? places 地方

$stmt->bind_param('ss', ''.$typeok.'', $paramok);

You can read here what characters should be used when using numbers, strings or such: 您可以在此处阅读使用数字,字符串等时应使用哪些字符:
http://php.net/manual/en/mysqli-stmt.bind-param.php http://php.net/manual/en/mysqli-stmt.bind-param.php

types 类型

A string that contains one or more characters which specify the types for the corresponding bind variables: 一个包含一个或多个字符的字符串,这些字符指定相应绑定变量的类型:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:mysqli_stmt::bind_param():类型定义字符串中的元素数与绑定变量数不匹配 - Error: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables SQL错误:mysqli_stmt :: bind_param():类型定义字符串中的元素数量与绑定变量的数量不匹配 - SQL error :mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables bind_param 错误 - 类型定义字符串中的元素数与绑定变量数不匹配 - bind_param error - Number of elements in type definition string doesn't match number of bind variables 警告:mysqli_stmt::bind_param():类型定义字符串中的元素数与绑定变量数不匹配 - Warning : mysqli_stmt::bind_param(): Number of elements in type definition string doesn’t match number of bind variables mysqli_stmt :: bind_param():类型定义字符串中的元素数量与绑定变量数量不匹配 - mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables warning mysqli_stmt::bind_param(): 类型定义字符串中的元素数与绑定变量数不匹配 - mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables mysqli_stmt :: bind_param():类型定义字符串中的元素数量与使用数组的绑定变量数量不匹配 - mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables using array mysqli_stmt::bind_param()类型定义字符串中的元素个数与个数不匹配 - mysqli_stmt::bind_param()Number of elements in type definition string doesn't match number mysqli错误-bind_param:变量数不匹配 - mysqli error - bind_param: number of variables doesn't match PHP警告:mysqli_stmt :: bind_param():类型定义字符串中的元素数与数字不匹配 - PHP Warning: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM