php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #58445 PDO does not fetch contents from all fields
Submitted: 2008-12-05 03:39 UTC Modified: 2009-03-02 07:17 UTC
Votes:3
Avg. Score:4.7 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:0 (0.0%)
Same OS:2 (66.7%)
From: tuomaksen dot spammiposti at gmail dot com Assigned:
Status: Open Package: PDO_IBM (PECL)
PHP Version: 5.1.6 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
41 - 38 = ?
Subscribe to this entry?

 
 [2008-12-05 03:39 UTC] tuomaksen dot spammiposti at gmail dot com
Description:
------------
I noticed a strange behaviour in fetching data from DB2 databases. With PDO_IBM some fields (type of VARLEN(?)) are returned as blank or in some case the field contents seem to be a text "Resource id #<num>" while in reality they contain text. Otherwise the query returns the correct data. 

Using the db2_* -functions on the fields are returned ok.

Reproduce code:
---------------
<?php
/** Does not work **/
$db = new PDO($dsn,$user,$pass);
$result = $db->query('SELECT * FROM table');
$matrix = $result->fetchAll(PDO::FETCH_ASSOC);
echo "<table>\n";
foreach($matrix as $row) {
	echo "<tr>\n";
	foreach($row as $cell) {
		echo "<td>$cell</td>\n";
	}
	echo "</tr>\n";
}
echo "</table>\n";

/** This seems to work **/
$conn = db2_connect($db,$user,$pass);
$prep = db2_prepare($conn,'SELECT * FROM table');
db2_execute($prep);
while($row = db2_fetch_assoc($prep) {
        echo "<tr>\n";
        foreach($row as $item) {
                echo "<td>$item</td>\n";
        }
        echo "</tr>\n";
}
?>

Expected result:
----------------
Fields type of VARLEN(?) should contain data.

Actual result:
--------------
Field is returned as empty or in some cases field contains text "Resource id #<num>". Other fields are displayed correctly.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-12-09 08:19 UTC] tuomaksen dot spammiposti at gmail dot com
Here is the structure of the table whom contents I tried to fetch (column type and length):
CHAR(6),
DECIMAL(7),
CHAR(10),
CHAR(10),
CHAR(3),
LONG VARCHAR(12000),
LONG VARCHAR(8000),
CHAR(10),
CHAR(256),
DECIMAL(11),
DECIMAL(13),
DATE(10),
CHAR(20),
CHAR(20),
CHAR(20),
TIMESTAMP(26),
CHAR(20),
CHAR(20),
CHAR(20),
TIMESTAMP(26)

The two LONG VARCHAR columns are the ones that are fetched as empty while in reality also they contain data. Other columns seem to be fetched correctly.
 [2008-12-12 04:47 UTC] tuomaksen dot spammiposti at gmail dot com
Just updated to 1.3.0 and now the result is that when I make a query where a LONG VARCHAR column is included, PHP segfaults.
 [2008-12-15 02:15 UTC] abhargav at in dot ibm dot com
Hi,

What was the version of PDO_IBM extension that you were using, which was not giving you segfault but giving you wrong results?

Regards,
Ambrish Bhargava
 [2008-12-15 05:16 UTC] tuomaksen dot spammiposti at gmail dot com
Hi!

Version 1.2.5. was the one giving me false results.
 [2008-12-15 05:18 UTC] abhargav at in dot ibm dot com
Hi,

I am looking into this issue and will get back to you.

Regards,
Ambrish Bhargava
 [2009-03-02 06:14 UTC] abhargav at in dot ibm dot com
Hi,

Sorry for late response. I have a question over here: What is the version DB2 that you are using (db2level)?

I was searching for LONG VARCHAR datatype and found that it is depricated from v9.5.0.1 onwards. I suggest to use CLOB instead of LONG VARCHAR. For reference, please visit http://publib.boulder.ibm.com/infocenter/db2luw/v9r5/topic/com.ibm.db2.luw.wn.doc/doc/i0053661.html.

Regards,
Ambrish Bhargava
 [2009-03-02 06:36 UTC] tuomaksen dot spammiposti at gmail dot com
-clip-
DB21085I  Instance "db2inst1" uses "32" bits and DB2 code release "SQL08027"
with level identifier "03080106".
Informational tokens are "DB2 v8.1.2.128", "s061108", "MI00176", and FixPak
"14".
Product is installed at "/opt/IBM/db2/V8.1".
-clip-

The DB2 server is located on another server (i5 5.4). I'm not responsible for the i5 server but I believe that converting field types might cause other problems.
 [2009-03-02 07:17 UTC] abhargav at in dot ibm dot com
Ok...

Now, I realize why I was not able to reproduce this problem.

Can you provide me following things:
1. The create table statement that you have used.
2. The CLI trace which got generated when you execute the sample provided in this thread using PDO_IBM and IBM_DB2 (separately).

Regards,
Ambrish Bhargava
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Tue Jun 18 05:01:27 2019 UTC