我有一个数据阵列,例如这个:
$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用值替换我的部分键吗?
那有什么不对?
谢谢你的协助。
编辑:执行确实可以使用命名绑定,因此您可以像这样编辑$ 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);