连续两次重复查询时出现奇怪的不一致 [英] Strange inconsistences when repeating a query more than twice in a row

查看:94
本文介绍了连续两次重复查询时出现奇怪的不一致的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我用PHP编写的一个小示例程序(运行Apache

1.3.31 w / PHP 5.0.1)来帮助说明我遇到的问题。数据

base使用的是DB2 V5R3M0。客户端是WinXP机器,使用iSeries

客户端访问驱动程序ver 10.00.04.00连接到数据库。


问题是执行完全相同的SQL select语句更多

比连续两次停止产生结果。前两个实例

将始终产生正确的结果,但之后它将简单地返回
返回,但未找到任何结果。我还用其他各种ODBC API编写了完全相同的测试用例

,结果相同。


我检查了ODBC驱动程序跟踪日志,我无法找到产生正确的结果的SQL语句与产生无结果的消息之间的任何明显的差异。我已经尝试了三个不同的ODBC驱动程序版本,并且具有相同的结果。


注意:对于每个选择语句都不会发生这种情况但是它对于具有各种WHERE子句的不同文件确实发生了
但是我无法确定
确定工作和非工作重复之间的任何关系

select语句。


PHP源代码:


< html> <身体GT; <?php

$ connect = odbc_connect(" AS400","","",SQL_CUR_USE_ODBC);

if($ connect == false )

printf(连接到数据库的问题);

/ *已经创建

$ query =" CREATE TABLE EJWLIB。 BHEADW(" ;;

$ query。=" BATCHNUM NUMERIC(5)NOT NULL," ;;

$ query。=" COMPID CHAR(2)NOT NULL," ;;

$ query。=" AMOUNT NUMERIC(9,2)NOT NULL," ;;

$ query。=" BDATE DATE NOT NULL ,;

$ query。=" EDIREF CHAR(15)," ;;

$ query。=" FLAG CHAR(1)NOT NULL)" ;;

$ result = odbc_exec($ connect,$ qu ** ery); * /


$ query =" DELETE FROM EJWLIB.BHEADW";

$ result = odbc_exec($ connect,$ qu ** ery);


$ query =" INSERT INTO EJWLIB.BHEADW VALUES('''',''FX'','''361.94'',

' '04 / 22/2005'',''305855545'',''O'')" ;;

$ result = odbc_exec($ connect,$ qu ** ery);


$ i = 0; $ query =" SELECT BATCHNUM FROM EJWLIB.BHEADW WHERE AMOUNT =

''361.94''AND COMPID =''FX''" ;;

while($ i < 5){

$ result = odbc_exec($ connect,$ qu ** ery);

if(!$ result)

echo(" failed< br>");

$ rows = odbc_result_all($ result,**" border = 1");

$ i ++;

}


odbc_close($ connect);

?> < /体> < / html>


计划产出


< html>

< body>

< table border = 1>< tr>< th> BATCHNUM< / th>< / tr>

< tr>< td> 1< / td>< / tr>

< / table>

< table border = 1>< tr>< th> BATCHNUM< / th>< ; / tr>

< tr>< td> 1< / td>< / tr>

< / table>

< h2>未找到任何行< / h2>

< h2>未找到任何行< / h2>

< h2>未找到任何行< / h2>

< / body>

< / html>

解决方案

connect = odbc_connect(" AS400","" ;,",",SQL_CUR_USE_ODBC);

if(


connect == false)

printf(&连接问题)到数据库);

/ *已经创建


query =" CREATE TABLE EJWLIB.BHEADW(" ;;

Here is a small sample program I wrote in PHP (running off Apache
1.3.31 w/ PHP 5.0.1) to help illustrates problem I''m having. The data
base is using DB2 V5R3M0. The client is WinXP machine using the iSeries
Client Access Driver ver 10.00.04.00 to connect to the database.

The problem is that executing the exact same SQL select statement more
than twice int a row stops produces results. The first two instances
will always produce the correct results but after that it will simply
return with no results found. I''ve also wrote the exact same test case
with other various ODBC APIs with the same results.

I''ve examining the ODBC driver trace log and I am unable to find any
noticable differences between a SQL statement producing the correct
results and one that produces a no results found message. I''ve tried
three different ODBC driver versions and have the same results.

NOTE: This doesn''t occur for EVERY select statement but it does occur
for different files with various WHERE clauses but I''ve been unable to
determine any relationship between working and non working repeating
select statements.

PHP SOURCE CODE:

<html> <body> <?php
$connect = odbc_connect ("AS400", "","",SQL_CUR_USE_ODBC);
if ($connect == false)
printf("Problem connecting to the database");
/* Already created
$query = "CREATE TABLE EJWLIB.BHEADW ( ";
$query .="BATCHNUM NUMERIC(5) NOT NULL, ";
$query .="COMPID CHAR(2) NOT NULL, ";
$query .="AMOUNT NUMERIC(9,2) NOT NULL, ";
$query .="BDATE DATE NOT NULL, ";
$query .="EDIREF CHAR(15), ";
$query .="FLAG CHAR(1) NOT NULL)";
$result=odbc_exec($connect,$qu**ery); */

$query = "DELETE FROM EJWLIB.BHEADW";
$result=odbc_exec($connect,$qu**ery);

$query = "INSERT INTO EJWLIB.BHEADW VALUES(''1'', ''FX'', ''361.94'',
''04/22/2005'', ''305855545'', ''O'')";
$result=odbc_exec($connect,$qu**ery);

$i=0; $query="SELECT BATCHNUM FROM EJWLIB.BHEADW WHERE AMOUNT =
''361.94'' AND COMPID = ''FX''";
while ($i < 5) {
$result=odbc_exec($connect,$qu**ery);
if (!$result)
echo("failed <br>");
$rows=odbc_result_all($result,**"border=1");
$i++;
}

odbc_close($connect);
?> </body> </html>

PROGRAM OUTPUT

<html>
<body>
<table border=1 ><tr><th>BATCHNUM</th></tr>
<tr><td>1</td></tr>
</table>
<table border=1 ><tr><th>BATCHNUM</th></tr>
<tr><td>1</td></tr>
</table>
<h2>No rows found</h2>
<h2>No rows found</h2>
<h2>No rows found</h2>
</body>
</html>

解决方案

connect = odbc_connect ("AS400", "","",SQL_CUR_USE_ODBC);
if (


connect == false)
printf("Problem connecting to the database");
/* Already created


query = "CREATE TABLE EJWLIB.BHEADW ( ";


这篇关于连续两次重复查询时出现奇怪的不一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆