我仍然在通过php调用db2中的存储过程方面遇到问题。 我终于可以调用它并获取打印错误了,但我不明白为什么会收到这些当前错误。
while循环之前的第一位很好,选择适当的数据。然后,我对该数据进行循环,将返回的行绑定为参数,并对这些参数执行存储过程调用。在我的while循环中的捕获中(在打印选定数据之后),我得到了错误:
PROC FAILED: SQLSTATE23000: Integrity Constraint violation: -803......Dupicate key value specified
现在,我确实在此表上设置了关键约束,但是奇怪的是,我在一个空表上调用了此过程,因此不可能尝试插入重复项。另外,如果我从错误行之一获取数据集并通过在IDE中调用proc手动将其插入,则会插入ok。
还有其他可能导致此错误的东西吗?
$sql = "
SELECT
CAST(NUMBER as int) as NUMBER,
CAST('Test List' as VARCHAR(50)) as LIST,
CAST(NAME as int) AS NAME,
CAST(GROUPING as varchar(50)) AS GROUPING,
CAST(DETAIL1 as int) AS DETAIL1,
CAST(DETAIL2 as int) AS DETAIL2,
CAST(DETAIL2NAME as varchar(50)) AS DETAIL2NAME,
CAST(CATEGORY as varchar(50)) as CATEGORY,
CAST('None' as varchar(256)) as COMMENTS
from productTest p
GROUP BY NUMBER, NAME,GROUPING,DETAIL1,DETAIL2,DETAIL2NAME,CATEGORY
order by NUMBER
";
try {
$getRows = $DB2connProd->prepare($sql);
$numResult = $getRows->execute();
}catch(PDOException $ex) {
$OrdSlctError = "ORDER SELECT FAILED!: " .$ex->getMessage();
print_r($OrdSlctError);
}
while ($orderRow = $getRows->fetch(PDO::FETCH_ASSOC)) {
print_r($orderRow);
$proc = "CALL TEST . TEST_INSERT(?, ?, ?, ?, ?, ?, ?, ?, ?, DEFAULT, DEFAULT)";
try{
$callProc = $DB2connProd->prepare($proc);
$callProc->bindParam(1, $orderRow["NUMBER"], PDO::PARAM_INT, 10);
$callProc->bindParam(2, $orderRow["LIST"], PDO::PARAM_STR, 50);
$callProc->bindParam(3, $orderRow["NAME"], PDO::PARAM_INT, 10);
$callProc->bindParam(4, $orderRow["GROUPING"], PDO::PARAM_STR,50);
$callProc->bindParam(5, $orderRow["DETAIL1"], PDO::PARAM_INT, 10);
$callProc->bindParam(6, $orderRow["DETAIL2"], PDO::PARAM_INT, 10);
$callProc->bindParam(7, $orderRow["DETAIL2NAME"], PDO::PARAM_STR, 50);
$callProc->bindParam(8, $orderRow["CATEGORY"], PDO::PARAM_STR, 50);
$callProc->bindParam(9, $orderRow["COMMENTS"], PDO::PARAM_STR, 256);
$callProc->execute();
print_r($callProc);
}catch(PDOException $ex){
echo "PROC FAILED!: " .$ex->getMessage();
}
}