PDO-动态bindParam-值为0的奇怪结果 [英] PDO - Dynamic bindParam - value of 0 strange result
本文介绍了PDO-动态bindParam-值为0的奇怪结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,由于这里用户的建议,我开始将代码移植到PDO.一切顺利,直到出现一个小问题.
我有一个小函数来处理数据库调用,该函数基本上会生成SQL查询,执行$ dbh->准备($ sql),然后遍历并绑定值,然后执行查询.
$sth = $dbh->prepare ($sql);
// bind parameters
if ($action == 'insert' || $action == 'update') {
reset ($array);
foreach ($array as $key => &$value) {
if ($value != 'NOW()') {
$sth->bindParam (':' . $key, $value);
}
}
}
$sth->execute();
在我需要插入值'0'之前,它可以正常工作.没有错误返回,但是插入到数据库中的值原来是表中列类型的最大值,在这种情况下为"137".
我希望有人可以解释正在发生的事情以及提供解决方案,而不是仅仅给我一个解决办法,以便我可以更好地理解这一点.
干杯, 卢克
解决方案
您没有正确绑定参数,请查看
I'd prefer if someone could explain what is happening as well as providing a solution rather than just give me a fix so I can better understand this. Cheers,
Luke You're not binding the parameters correctly, check out the manual.
这篇关于PDO-动态bindParam-值为0的奇怪结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! 解决方案
You should use:$sth->bindParam (':' . $value, [PARAM TYPE - example: PDO::PARAM_INT]);
查看全文