|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-11-16 14:48 UTC] michael dot caplan at lechateau dot ca
Description:
------------
I'm not 100% sure if this is a bug, or just a 'quirk', but my attempt to get feedback on this issue on the php db support list was unsuccessful. So, here I am....
I am selecting multiple columns from a table, one being a clob. the query returns multiple records for the query. The results are all good, execpt the clob column in certain circumstances.
Normally, with such a db return, I would loop through the results and grab the clobs one by one. Under 'special' circumstances, I would want to first loop throught the results and assign the results to a new array before fetching the clob. This is where things get funky. In this senario, the last returned record's clob column overwrites all previous clob columns (all the previous records have there unique data, except the clob columns which contains the data for the last record across all previous records).
A working example:
$query = 'select
id,
author,
cdate,
views,
title,
message,
top
from
APP_THREADS
where
TYPE = \'D\'';
$stmt = ociparse($fw_db->connection, $query);
ociexecute($stmt);
while (OCIFetchInto ($stmt, $row, OCI_ASSOC)) {
echo $row['MESSAGE']->load();
echo $row['id'];
// etc....
}
as expected, I get all clobs from the result set. But in this example, I do not:
$query = 'select
id,
author,
cdate,
views,
title,
message,
top
from
APP_THREADS
where
TYPE = \'D\'';
$stmt = ociparse($fw_db->connection, $query);
ociexecute($stmt);
while (OCIFetchInto ($stmt, $row, OCI_ASSOC)) {
// assign all lob resources to array for later loading
$messages[] = $row['MESSAGE'];
}
foreach ($messages as $message) {
echo $message->load();
}
In this example, the last assigned lob resource overwrites all previous lob resources. When fetching the clob content later on, each record returns the data from the last lob.
I am pretty unawair of the internal mechanics of how resources are handled, and this just might be a quirk of how db result resources for oci8 are handled, and is unavoidable. (it looks like one resource is returned for all lobs, not multiple resources for each lob).
However, it is a pretty counter intuitive 'quirk'. If I can loop through the results and assign all non resource elements to an array for later operations, should I not be able to do the same thing with resources?
Thanks.
Michael
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 15:00:01 2025 UTC |
It was a little difficult to test -- php kept on segfaulting with the DB abstraction lib I normaily use. I tried a new test as follows, but unfortunately I had the same results: CREATE TABLE "INTRANET"."CLOB_TEST" ( "ID" NUMBER NOT NULL ENABLE, "TEXT_TEXT" VARCHAR2(500) NOT NULL ENABLE, "CLOB_TEXT" CLOB, PRIMARY KEY ("ID") ) ID TEXT_TEXT CLOB_TEXT -- --------- ----------------- 1 text1 this is a clob of text1 2 text2 this is a clob of text2 3 text3 this is a clob of text3 4 text4 this is a clob of text4 5 text5 this is a clob of text5 <?php $db = ocinlogon('intranet', 'stidemoron', 'webdev'); $query = 'select ID, TEXT_TEXT, CLOB_TEXT from CLOB_TEST'; $stmt = ociparse($db, $query); ociexecute($stmt); while (OCIFetchInto ($stmt, $row, OCI_ASSOC)) { echo $row['ID'] . "\r\n"; echo $row['TEXT_TEXT'] . "\r\n"; echo $row['CLOB_TEXT']->load() . "\r\n"; } echo "----2-----\r\n"; $stmt = ociparse($db, $query); ociexecute($stmt); $res = array(); while (OCIFetchInto ($stmt, $row, OCI_ASSOC)) { $res[] = $row['CLOB_TEXT']; } foreach($res as $r) { echo $r->load() . "\r\n"; } ?> results: 1 text1 this is a clob of text1 2 text2 this is a clob of text2 3 text3 this is a clob of text3 4 text4 this is a clob of text4 5 text5 this is a clob of text5 ----2----- this is a clob of text5 this is a clob of text5 this is a clob of text5 this is a clob of text5 this is a clob of text5Well, echo $row['CLOB_TEXT']->load(); is not exactly the same as $res[] = $row['CLOB_TEXT']; In the last one you are assigning the whole object to an element of an array. This may be the reason it overwrites all the rest. Try this: $res[] = $row['CLOB_TEXT']->load(); and the print as foreach($res as $r) { echo $r . "\r\n"; } Just my guess. maxim