English 中文(简体)
db2_ fetch_ assoc () 即使存在, 即便有, 也不会返回下一行
原标题:db2_fetch_assoc() not returning the next row even when one exists
  • 时间:2012-05-25 01:34:40
  •  标签:
  • php
  • db2

db2_ fetch_ assoc () 在从某些地方调用时找不到下一行 - 尽管记录板上有更多行 。

go查询DB2() 连接到数据库并运行查询。 它能够使用 db2_ fetch_ assoc () 和 recordet () 中的第二行返回记录框中的第一行, 并调用外部函数获取 NextRowDB2( ) 。

从此函数返回记录板资源( 结果 ) 。 然而, 当获得下RextRowDB2( ) 时, 以 $Blus 提供参数再次调用 $Blus 时, 记录板中的第三行没有返回 - 事实上它找不到任何东西, 并发出警告( 警告: db2_ fetch_assoc () [ 函数. db2- fetch-assoc] : Fetch Dault) 。

您可以从“ 在 资源 id # 12 中找不到结果” 的输出中看到, 资源的名称已被有效传递到获取下RowDB2( 2) 函数 - 但出于某种原因, 它在该记录板中找不到任何行 。

有人能告诉我发生了什么吗?

是否有什么东西使得 DB2 记录资源无法在它被命名的函数之外进入?

在 MySQL (我必须转换为 DB2) < strong > this works ok in MySQL ( <% 1\\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ < \ \ \ \ \ \\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \

所以这个代码:

function goQueryDB2($sql)
{
  if($con = db2_connect("MASTER", "USER", "PASSWORD"))
  {
    echo "<li>Connected to master database</li>";   
  }

  if($result = db2_exec($con, $sql))
  {
    echo "<li>SQL Query ran successfully</li>"; 
  }

  //Just proving some data can be returned as this point
  $row = db2_fetch_assoc($result);

  if(sizeof($row) > 0)
  {
    echo "<li>db2_fetch_assoc returned a record in the resultset (Resource ID: " . $result . ") that has " . sizeof($row) . " fields</li>"; 
  }

  //Just proving some data can be returned as this point
  $row = getNextRowDB2($result);
  if(sizeof($row) > 0)
  {
    echo "<li>getNextRow() returned a record in the resultset (Resource ID: " . $result . ") the has " . sizeof($row) . " fields</li>"; 
  }

  return $result;
}

function getNextRowDB2($result)
{
    if($row = db2_fetch_assoc($result))
    {
        return $row;    
    }
    else
    {
        echo "<li>No results found in " . $result . "</li>";    
    }
}

echo "<h2>goQueryDB2()</h2>";
$result = goQueryDB2("SELECT * FROM users");

echo "<h2>getNextRowDB2()</h2>";
$row = getNextRowDB2($result);

生成此输出 :

goQueryDB2()
Connected to master database
SQL Query ran successfully
db2_fetch_assoc returned a record in the resultset (Resource ID: Resource id #12) that has 25 fields
getNextRow() returned a record in the resultset (Resource ID: Resource id #12) the has 25 fields
getNextRowDB2()

Warning: db2_fetch_assoc() [function.db2-fetch-assoc]: Fetch Failure in /home/portal/includes/functionsSecurity.php on line 262
No results found in Resource id #12
问题回答

我用一个持续的联系解决了问题:

$con = db2_pconnect("MASTER", "USER", "PASSWORD")

我假定,即使资源的名称(“资源 ID #12”)从函数中回传, DB2 连接和所有返回的资源在其被调用的函数结束时都不再存在,除非使用持续的连接。

这是DB2独有的,因为我发现在 MySQL 中,没有必要长期连接来实现这一点。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签