大佬教程收集整理的这篇文章主要介绍了PHP-mysqli和bound语句,2031:语句中无参数数据,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我的代码,不起作用,不知道为什么:
@H_404_4@$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()结果为:
@H_404_4@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打印输出.
附言在设置所有这三个变量之前,都有一个链,但是它们确实包含所需的内容!
@H_404_4@// $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.2与MysqLnd吗?而且,是的,在本地主机上,我使用默认的MysqL驱动程序运行5.2.6,在生产服务器上,PHP使用MysqLnd运行5.3.5版本.
解决方法:
在对http://bugs.php.net/bug.php?id=43568进行了更多研究之后,我设法通过替换以下内容解决了该问题:
@H_404_4@foreach($array as $k=>&$v){
$params[] =& $v;
}
if($update && $_updatE) $params = array_merge($params, $_updatE); # this is the actual line, that I've replaced
与:
@H_404_4@// 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如何允许常量值绑定,而5.3则不允许.无论如何,我很高兴我已经解决了这个问题,希望以后对其他人有帮助.
这实际上解释了为什么无论版本如何都可以执行插入操作…这些值开始时都被引用变量填充.
以上是大佬教程为你收集整理的PHP-mysqli和bound语句,2031:语句中无参数数据全部内容,希望文章能够帮你解决PHP-mysqli和bound语句,2031:语句中无参数数据所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。