我正在嘗試在PHP中運(yùn)行db2參數(shù)化查詢,并且在執(zhí)行插入時,我收到錯誤:Invalid parameter number., SQL state S1002 in SQLDescribeParameter這是我的腳本: $getItems = " SELECT ID, EXPIRATION_TIMESTAMP FROM table1 "; $stmt = odbc_exec($DB2connDEV, $getItems); $prepInsert = odbc_prepare($DB2connPROD, "INSERT INTO table2 (originalID, expiration_timestamp) VALUES(?,?)"); while($gettingDevItems = odbc_fetch_array($stmt)){ $rows[] = $gettingDevItems; } foreach($rows as $row){ $originalID = $row['ID']; $expiration_timestamp = $row['EXPIRATION_TIMESTAMP']; $getIdentity = "SELECT IDENTITY_VAL_LOCAL() AS LASTID FROM SYSIBM.SYSDUMMY1"; $insertTable = odbc_execute($prepInsert, array($originalID, $expiration_timestamp));//error at this line $insertTable = odbc_exec($DB2connPROD, $getIdentity); $row = odbc_fetch_array($stmt); $ret = $row['LASTID']; }當(dāng)我對參數(shù)數(shù)組進(jìn)行var_dump時,我得到這個:array(2) { [0]=>string(1) "2" [1]=>string(26) "2019-10-03 00:00:00.000000"}我在這里做錯了什么?即使我取出一個值以僅插入一個或另一個值,我仍然會得到它,因此它不特定于一列。
1 回答

九州編程
TA貢獻(xiàn)1785條經(jīng)驗 獲得超4個贊
也許 odbc 不能支持重用預(yù)準(zhǔn)備語句、驅(qū)動程序、代碼的其他部分或其他內(nèi)容。無論如何,將準(zhǔn)備好的語句移動到 foreach 循環(huán)中,以確保將重新生成它:
foreach($rows as $row){ $prepInsert = odbc_prepare($DB2connPROD, "INSERT INTO table2 (originalID, expiration_timestamp) VALUES(?,?)"); ...
- 1 回答
- 0 關(guān)注
- 79 瀏覽
添加回答
舉報
0/150
提交
取消