【发布时间】:2018-03-09 04:54:28
【问题描述】:
我正在尝试使用 PDO 修复 php 脚本中的 mysql 更新。
我有一个包含正确记录的数组 $order_ids,然后我使用一个名为 $placeholders 的变量为我的选择查询 $detailstatcheck 内爆这些值。
所有这些都有效,但我在底部添加的更新不起作用,当我运行脚本时,它会打印出 0 条记录已更新。
我只想说“如果 order_id 在 $order_ids 或 $placeholders 中,则更新记录”
$order_ids = [];
while ($row = $ordStat->fetch(PDO::FETCH_ASSOC)) {
$order_ids[] = $row['order_id'];
}
if (count($order_ids) > 0) {
$placeholders = implode(',', array_fill(0, count($order_ids), '?'));
//This query works
$detailStatCheck = "
SELECT
invnoc as INVOICE,
fstatc as STATUS,
cstnoc AS DEALER,
framec AS FRAME,
covr1c AS COVER,
colr1c AS COLOR ,
extd2d AS SHIPDATE,
orqtyc AS QUANTITY
FROM GPORPCFL
WHERE invnoc IN ($placeholders)
";
try {
$detailCheck = $DB2conn->prepare($detailStatCheck);
$detailRslt = $detailCheck->execute($order_ids);
$count2 = $detailCheck->fetch();
print_r($order_ids);
print_r($count2);
} catch(PDOException $ex) {
echo "QUERY FAILED!: " .$ex->getMessage();
}
//this update doesn't work
$updateShipped = "
UPDATE order_status
set date_updated = current_date()
where order_id in ($placeholders) //Not sure if syntax is correct here
";
try{
$updateStatus = $MysqlConn->prepare($updateShipped);
$statUpdateRslt = $updateStatus->execute();
$count = $updateStatus->rowcount();
}
catch(PDOException $ex)
{
echo "QUERY FAILED!: " .$ex->getMessage();
}
echo "Records Updated: " . $count . "\n";
更新:
order_status 表结构
order_id | order_status | is_placement | date_updated
-----------------------------------------------------------
12345 S 1 2018-03-09
order_id = int(11)
order_status = varchar
is_placement = 位
date_updated = 日期
【问题讨论】:
-
我现在收到了
QUERY FAILED!: SQLSTATE[HY093]: Invalid parameter number: no parameters were boundRecords Updated: 0 -
请用虚拟条目显示您的 order_status 表的结构。
-
我已经添加了