我正在嘗試在PHP中運行db2參數化查詢,并且在執行插入時,我收到錯誤: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']; }當我對參數數組進行var_dump時,我得到這個:array(2) { [0]=>string(1) "2" [1]=>string(26) "2019-10-03 00:00:00.000000"}我在這里做錯了什么?即使我取出一個值以僅插入一個或另一個值,我仍然會得到它,因此它不特定于一列。
1 回答

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