从命令行运行时的当前错误是“调用非对象上的成员函数 bindParam()”,我发现这是变量 $orderPO 的问题。有些东西不喜欢非数字字符,这导致我使用了也不起作用的 bindParam PARAM_STR 业务。数据库字段都是 varchar 50。
我的搜索技巧让我失望了。我知道这必须在某个地方发布大约一百万次,但我似乎找不到它。如果有人有更好的主意,我完全愿意以另一种方式这样做。
当前尝试代码:
try
{
$orderNum = '123456';
$orderPO = '123456-A';
$dbh = new PDO("mysql:host=localhost;dbname=dbname", 'someuser', 'somepass');
$stm = $dbh->prepare("insert into some_table (order_number, order_po)");
$stm->bindParam(':order_number', $orderNum, PDO::PARAM_STR);
$stm->bindParam(':order_po', $orderPO, PDO::PARAM_STR);
$stm->execute();
print_r($stm);
print_r($dbh);
$arr = $stm->errorInfo();
print_r($arr);
$stm->closeCursor();
$dbh = null;
}
catch(PDOException $e)
{
echo $e->getMessage();
}