我有一个数据数组,例如:
$data = ['ver_weather' => $post["weathercondition"],
'ver_flash' => $post["flashintense"],
'ver_earth' => $post["earthrumble"]]
我在 sql 中使用的这些数据如下:
$sql = "INSERT INTO `database`.`table` (`weather`, `flash`, `earth`)
VALUES (:ver_weather, :ver_flash, :ver_eart)";
$pdo->prepare($sql)->execute($data);
结果是这样的:
INSERT INTO `database`.`table` (`weather`, 'flash', `earth')
VALUES ('1'weather, '1'flash, '1'earth)
那么 pdo 是否用值替换了我的部分密钥?
有什么问题吗?
谢谢你的协助。
编辑: Execute 确实适用于命名绑定,因此您可以像这样编辑 $data 数组:
$data = [':ver_weather' => $post["weathercondition"],
':ver_flash' => $post["flashintense"],
':ver_earth' => $post["earthrumble"]]
注意:在每个键的开头
原答案如下...
我认为问题在于您试图按名称绑定,并且我认为 PDOStatement 不支持命名绑定。我建议尝试以下方法:
$data = [$post["weathercondition"], $post["flashintense"], $post["earthrumble"]];
$sql = "INSERT INTO `database`.`table` (`weather`, `flash`, `earth`)
VALUES (?, ?, ?)";
$pdo->prepare($sql)->execute($data);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句