【问题标题】:bind_param number of elements doesn't match number of element arraybind_param 元素数量与元素数组数量不匹配
【发布时间】:2017-06-13 18:56:21
【问题描述】:

你好,我有一个关于 bind_param 的问题,每个代码都有效,但不是这个......可能是愚蠢的问题..

$key = "`".implode("`, `",array_keys($notifikasi))."`";
echo $value = "'".implode("', '",array_values($notifikasi))."'";
$query = $dbcon->prepare("INSERT INTO `notifikasi` ($key) VALUES ($value)");
$query->bind_param("iiiis",$value);
$query->execute();

我已经回显了这个值:

'1','1','2','3','profile.php?confirm=33'

我在 bind_param 上放了任何数字仍然出现此错误:

mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables  

谁能回答我的误解?

[编辑] 没关系,我找到了解决方案:
使用 call_user_func_array()

mysqli bind_param for array of strings

谢谢

【问题讨论】:

  • 您没有正确绑定参数。查询字符串应包含 ?:foo 等占位符,而不是您的实际值。有关示例,请参阅bind_param 的文档。
  • 我已经阅读了文档,是的,它应该放吗?
    所以我将其置于准备状态 (?,?,?,?,?) bind_param (iiiis,$value)。
    我的问题与数组有关吗?还是错误

标签: php arrays bind bindparam


【解决方案1】:

问题是您尝试绑定参数时没有为它们添加任何占位符。

你永远不应该相信用户的输入,所以我建议你不要从输入中填充列名。我会修复查询中的列名:

$notifikasi = [1, 2, 'profile'];
$query = $dbcon->prepare("INSERT INTO `notifikasi` (col1, col2, col3) VALUES (?, ?, ?)");
$query->bind_param("iis", $notifikasi);

【讨论】:

    猜你喜欢
    • 2013-06-18
    • 2016-06-02
    • 1970-01-01
    • 2015-09-20
    • 1970-01-01
    • 1970-01-01
    • 2015-05-23
    • 1970-01-01
    • 2019-01-05
    相关资源
    最近更新 更多