PHP stream_get_contents()行为异常,无法从数据库中读取LOB

问题描述:

我在具有相似CLOB数据的表中有2条记录.每个查询都从查询中解析出来,然后由php在针对返回的PDO :: FETCH_ASSOC

I have 2 records in a table with similar CLOB data. Each of those are parsed from a query and then read into a string by php in a loop against the returned PDO::FETCH_ASSOC

查询返回结果后,它看起来像这样:

it looks something like this after the query returns the results:

ID   |   NAME   |   DESCRIPTION   |   LOB_DEFINITION
4409     foo        blah blah         long text that is stored in a lob ~ 5k characters
4410     foobar     blah blah         some other long text stored in a lob ~ 5k characters

我的问题是,一旦我开始循环遍历并从LOB读取内容,它们就不会重置",因此,读取的所有对象的值都与读取的第一个LOB相同:

My problem is that once I start looping through this and reading contents from the LOBs they don't 'reset' So, any and all of the objects read will have the same values as the first LOB it read:

类似这样的东西:

foreach($result as $r) {
$lob = stream_get_contents($r['LOB_DEFINITION']);
echo $r['ID'].'-<i>'.$lob.'</i><HR>';
unset($lob);
}

结果显示如下:

4409- 存储在一个lob中的长文本〜5k个字符

4410- 存储在一个lob中的长文本〜5k个字符

而不是我希望得到的是:

4409- 存储在一个lob中的长文本〜5k个字符

4410- 一些其他长文本存储在一个lob中〜5k个字符

我也检查了资源ID,它们是不同的资源...

I've checked the Resource IDs as well and they are different resources...

我在这里茫然...有人对这个问题有见识吗?

I'm at a loss here... Does anyone have insight on this subject?

几个小时的研究得出了以下结论:

Several hours of research resulted in the following:

从其中一个列是clob数据类型的oracle表返回多记录集,将导致最后检索到的clob记录成为所检索到的所有clob的值.这就是导致上述行为的原因.

returning a multi-record set from an oracle table where one of the columns is a clob datatype will result in the last record retrieved clob to be the value for ALL clobs retrieved. This is what was causing the behavior above.

我最终要解决的问题是首先:

What I ended up doing to solve the issue was first:

选择我计划使用Clob的所有记录(而不是Clob本身,仅记录ID)

selecting all the records in which I planned to work with clobs (not the clobs themselves, just the record IDs)

然后,我遍历这些记录ID,并通过单独的数据库调用使用主键将记录中的CLOB数据一一拖入,以确保不超过1条记录随Clob数据返回.所以本质上,这就是现在正在发生的事情:

I then loop through those record IDs and with separate database calls process the CLOB data 1 by 1 using the primary key to pull in the record to ensure no more than 1 record comes back with clob data. So in essence here is what is happening now:

从表中检索出我要使用的所有Clob的ID之后,我将通过它们进行解析:

after retrieving the ID from the table for all clobs I want to work with I parse through them thusly:

foreach($result as $r) {
  $query = 'select lob_definition from mytable where id = '.$r;
  $lobresult = oracleConnection->query($query)->fetchAll(FETCH_COLUM);
    $lob = stream_get_contents($lobresult);
    echo $r['ID'].'-<i>'.$lob.'</i><HR>';
    unset($lob);
}

某种效果解决了我的问题(所有方法都通过各种方法抽象化了,但是本质上就是这样了.

something to that effect has solved my problem (all of it is abstracted in various methods, but essentially that's what is happening.