db2_execute 返回“描述参数失败”和“绑定错误”
我正在使用 PHP 的 db2_prepare 和 db2_execute 运行以下查询(模式名称已更改以保护无辜者):
WITH U AS (
SELECT *
FROM FOO.USR
WHERE USR_ID = ?
), UC AS (
SELECT UC.*
FROM FOO.USR_CNTRCT UC
JOIN U ON U.USR_ID = UC.USR_ID
) , LC AS (
SELECT DISTINCT CNTRCT_ID
FROM FOO.CNTRCT_LOC CL
JOIN FOO.USR_LOC UL ON UL.SLS_CTR_CD = CL.SLS_CTR_CD
JOIN U ON U.USR_ID = UL.USR_ID
WHERE CL.SLS_CTR_CD IN (?,?,?,?)
)
SELECT C.*, COALESCE(P.PGM_NM, CAST('' AS CHAR(80) CCSID 37)) AS PGM_NM,
COALESCE(ADT.ACTN_TM, TIMESTAMP('2000001', '00.00.00')) AS TIME_ORDER
FROM U, FOO.CNTRCT AS C
LEFT JOIN FOO.CNTRCT_PGM CP ON CP.CNTRCT_ID = C.CNTRCT_ID
LEFT JOIN FOO.PGM P ON P.PGM_ID = CP.PGM_ID
LEFT JOIN UC ON UC.CNTRCT_ID = C.CNTRCT_ID
LEFT JOIN (
SELECT ENTY_ID AS CNTRCT_ID, MAX(ACTN_TM) AS ACTN_TM
FROM FOO.ADT A JOIN U ON U.USR_ID = A.USR_ID
WHERE ENTY_TP = 'CT'
GROUP BY ENTY_ID
) AS ADT ON ADT.CNTRCT_ID = C.CNTRCT_ID
WHERE C.APP = ?
AND (
((SELECT COUNT(*) FROM UC) > 0 AND UC.CNTRCT_ID IS NOT NULL)
OR
((SELECT COUNT(*) FROM UC) = 0 AND UC.CNTRCT_ID IS NULL)
)
AND ? BETWEEN YEAR(STRT_DT) AND YEAR(END_DT)
AND (LOWER(CNTRCT_NM) LIKE ?)
ORDER BY CNTRCT_NM ASC
我已经确认我的参数在数量和顺序上都是正确的。当我执行此查询时,php 返回两个错误:描述参数失败和绑定错误。
我已将问题范围缩小到这一行:CL.SLS_CTR_CD IN (?,?,?,?)
。如果我在这里使用实际值而不是参数,则查询运行良好。
环境是 Zend Server for IBM i、PHP 5.3、DB2 (on i) V6R1。我从作业日志(QEZJOBLOG)中获得的唯一帮助是 SQL0313(主机变量数量无效)。
我再次确认我提供了正确数量的变量。 描述参数失败错误让我想知道 PHP 是否正在努力确定这四个参数的类型。它们应该是 string(2)
类型,并且传递给 db2_execute 的参数数组的 var_dump 确认它们已被强制转换为此类。
我将改用该特定行的值而不是参数,但这会让我发疯,直到我弄清楚发生了什么。
谢谢
乍得
I'm running the following query using PHP's db2_prepare and db2_execute (schema names have been changed to protect the innocent):
WITH U AS (
SELECT *
FROM FOO.USR
WHERE USR_ID = ?
), UC AS (
SELECT UC.*
FROM FOO.USR_CNTRCT UC
JOIN U ON U.USR_ID = UC.USR_ID
) , LC AS (
SELECT DISTINCT CNTRCT_ID
FROM FOO.CNTRCT_LOC CL
JOIN FOO.USR_LOC UL ON UL.SLS_CTR_CD = CL.SLS_CTR_CD
JOIN U ON U.USR_ID = UL.USR_ID
WHERE CL.SLS_CTR_CD IN (?,?,?,?)
)
SELECT C.*, COALESCE(P.PGM_NM, CAST('' AS CHAR(80) CCSID 37)) AS PGM_NM,
COALESCE(ADT.ACTN_TM, TIMESTAMP('2000001', '00.00.00')) AS TIME_ORDER
FROM U, FOO.CNTRCT AS C
LEFT JOIN FOO.CNTRCT_PGM CP ON CP.CNTRCT_ID = C.CNTRCT_ID
LEFT JOIN FOO.PGM P ON P.PGM_ID = CP.PGM_ID
LEFT JOIN UC ON UC.CNTRCT_ID = C.CNTRCT_ID
LEFT JOIN (
SELECT ENTY_ID AS CNTRCT_ID, MAX(ACTN_TM) AS ACTN_TM
FROM FOO.ADT A JOIN U ON U.USR_ID = A.USR_ID
WHERE ENTY_TP = 'CT'
GROUP BY ENTY_ID
) AS ADT ON ADT.CNTRCT_ID = C.CNTRCT_ID
WHERE C.APP = ?
AND (
((SELECT COUNT(*) FROM UC) > 0 AND UC.CNTRCT_ID IS NOT NULL)
OR
((SELECT COUNT(*) FROM UC) = 0 AND UC.CNTRCT_ID IS NULL)
)
AND ? BETWEEN YEAR(STRT_DT) AND YEAR(END_DT)
AND (LOWER(CNTRCT_NM) LIKE ?)
ORDER BY CNTRCT_NM ASC
I've confirmed that my parameters are correct in number and in order. When I execute this query, php returns two errors: Describe Param Failed and Binding Error.
I've narrowed the problem down to this line: CL.SLS_CTR_CD IN (?,?,?,?)
. If I use actual values here instead of parameters, the query runs fine.
The environment is Zend Server for IBM i, PHP 5.3, DB2 (on i) V6R1. The only help I get from the job log (QEZJOBLOG) is an SQL0313 (Number of host variables not valid).
Again, I've confirmed that I'm providing the correct number of variables. The Describe Param Failed error makes me wonder if PHP is struggling to determine the type of those four parameters. They should be type string(2)
, and a var_dump of the parameter array passed to db2_execute confirms that they have been cast as such.
I'm going to switch to using the values instead of parameters for that specific line, but it's going to drive me crazy until I figure out what's going on.
Thanks
Chad
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在使用此 PTF 级别的复杂查询中绑定参数的 db2_prepare 和 db2_execute 遇到了一些问题:
升级到级别后
问题消失了,我又回到了宽容的疯狂级别:)
I had a few issues with db2_prepare and db2_execute whith bind params in complex queries with this PTFs level:
Upgrading to levels
the issues disappear and I was return to a permisive crazy level :)