gpt4 book ai didi

php - mysqli 和绑定(bind)语句,2031 : No data for parameters in statement

转载 作者:搜寻专家 更新时间:2023-10-31 20:53:00 25 4
gpt4 key购买 nike

这是我的代码,它不起作用,不知道为什么:

$sql = `INSERT INTO `_translations` (id, module, item_id, name_id, output, language) VALUES (?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE output = ?`
$stmt = mysqli_prepare($this->connection, $sql);
$params = array($stmt, $types);
foreach($array as $k=>&$v){
$params[] =& $v;
}
// this call is update call, therefore parameters are merged
if($update && $_update) $params = array_merge($params, $_update);
call_user_func_array('mysqli_stmt_bind_param', $params); # i think the problem is in this line..
if(mysqli_stmt_execute($stmt)){
if($this->transaction){ $this->affected++; }
else{ $this->affected = 1; }
}else{
$error = mysqli_stmt_error($stmt);
$errno = mysqli_stmt_errno($stmt);
die("{$sql}<br/><pre>".var_export($params, true)."</pre><br/>{$errno}: {$error}");
}

die() 结果:

INSERT INTO `_translations` (id, module, item_id, name_id, output, language) VALUES (?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE output = ?
array (
0 =>
mysqli_stmt::__set_state(array(
'affected_rows' => NULL,
'insert_id' => NULL,
'num_rows' => NULL,
'param_count' => NULL,
'field_count' => NULL,
'errno' => NULL,
'error' => NULL,
'sqlstate' => NULL,
'id' => NULL,
)),
1 => 'isissss',
2 => '',
3 => 'seo',
4 => '',
5 => 'keywords',
6 => 'tesoutput',
7 => 'en',
8 => 'tesoutput',
)

2031: No data supplied for parameters in prepared statement

好吧,类型计数等于参数,一切都应该工作正常,但事实并非如此。由于这个相同的函数用于简单的插入,我知道它可以工作...如果我需要更多数据,请随时询问。

有什么解决办法吗?

提前致谢!

更新#1:
这是 $array、$types 和 $update 的打印输出。
附言在设置所有这 3 个变量之前都有一个链,但它们恰好包含所需的内容!

// $array
array(6) {
["id"]=>
string(0) ""
["module"]=>
string(3) "seo"
["item_id"]=>
string(0) ""
["name_id"]=>
string(8) "keywords"
["output"]=>
string(9) "tesoutput"
["language"]=>
string(2) "en"
}
// $types
string(7) "isissss"
// $update
array(1) {
[0]=>
string(9) "tesoutput"
}

我已经想到问题可能出在 $types 字符串中,而不是处理 $array 值类型,因为那里所有的值都是字符串。不过,我不确定,因为在不更新的情况下插入时,它可以工作,即使这些是字符串。

更新#2:
看起来这是一个版本相关的错误,驱动程序错误 - http://bugs.php.net/bug.php?id=43568 ... 任何人都设法让 > 5.2mysqlnd 一起工作?而且,是的,在本地主机上,我使用默认的 mysql 驱动程序运行 5.2.6,在生产服务器上,PHP 运行版本 5.3.5mysqlnd

最佳答案

在对 http://bugs.php.net/bug.php?id=43568 进行更多研究之后,我已经设法通过替换来解决问题:

foreach($array as $k=>&$v){
$params[] =& $v;
}
if($update && $_update) $params = array_merge($params, $_update); # this is the actual line, that I've replaced

与:

// did a little housekeeping too
foreach($array as $k=>&$v) $params[] =& $v;
if($update && $_update) foreach($_update as $kk => $vv) $params[] =& $v; # instead of merging, I'm populating values the hard way.

哈,有趣的是 5.2 允许常量值绑定(bind),而 5.3 不允许。无论如何,我很高兴我已经解决了这个问题,我希望它能在未来帮助其他人。

这实际上解释了为什么 insert 无论版本如何都能正常工作...这些值从一开始就被引用变量填充。

关于php - mysqli 和绑定(bind)语句,2031 : No data for parameters in statement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5667977/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com