我所有的脚本都是用 pdo-mysql 编写的。现在我正在迁移到 posgresql。我一直卡在插入查询中。
CREATE TABLE bus_spot
(
bus_id integer NOT NULL,
spot_loc_id integer NOT NULL,
bus_dir_id integer NOT NULL
)
使用了 php 查询
$Bus_Id = 579;
$Bus_Dir_Id = 3;
$User_Loc_Id = 465;
$ISp_Res = $pdo->prepare("INSERT INTO bus_spot(bus_id, bus_dir_id, spot_loc_id) VALUES(?, ?, ?)");
$ISp_Res->execute(array($Bus_Id, $Bus_Dir_Id, $User_Loc_Id));
尝试插入这一行时出现以下错误
SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: \"\""}
最佳答案
在我看来,Postgres 对整数的输入格式有点挑剔。尝试使用适当的类型绑定(bind)参数,而不是将它们传递给隐式使用字符串的 execute()
方法
$ISp_Res = $pdo->prepare(...);
$ISp_Res->bindParam(1, $Bus_Id, PDO::PARAM_INT);
$ISp_Res->bindParam(2, $Bus_Dir_Id, PDO::PARAM_INT);
$ISp_Res->bindParam(3, $User_Loc_Id, PDO::PARAM_INT);
$ISp_Res->execute();
关于php - PDO 中的 Postgresql 插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22920115/