|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #468 Fetching LONG fields with odbc_result() behaves strange
Submitted: 1998-06-18 11:22 UTC Modified: 1998-06-24 11:05 UTC
From: woecherl at mlcomputing dot de Assigned:
Status: Closed Package: ODBC related
PHP Version: 3.0 Final Release OS: Windows NT 3.51
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 !
Your email address:
Solve the problem:
42 + 22 = ?
Subscribe to this entry?

 [1998-06-18 11:22 UTC] woecherl at mlcomputing dot de
The following script retrives a few columns from a table (via ODBC Visual Foxpro driver) including a field named 
"id" of SQL-type CHAR (length is 15) and a field named "desc" of SQL-type LONGVARCHAR, which is the interesting one:
	$sql = "select * from thetable";
	$conn = odbc_connect("thesource", "", "");
	if (!$conn) {
		echo '<h2>Error connecting to database.</h2>';
	} else {
		$curs = odbc_exec($conn, $sql);
		if ($curs) {
			echo '<center><table border>
			while (odbc_fetch_row($curs)) {
				$id = odbc_result($curs, 'id');
				$desc = odbc_result($curs, 'desc');
				echo "<tr><td>" . $id . "</td><td>" . $desc . "</td></tr>\n";
			echo '</table></center>';
		} else {
			echo 'Error querying datar.';
The "strange" behaviour is the following: Regardless how uodbc.defaultlrl and uodbc.defaultbinmode are set in php.ini,
the content of the field "desc" is inserted into output at the position of the line reading 
         $desc = odbc_result($curs, 'desc');
in my example. If odbc_result($curs, 'desc') is called once again, empty output until infinity is returned, whereas
subsequent calls to odbc_result($curs, 'id') work fine. I could not get PHP neither to assign the value of the field "desc" 
to a variable nor to pass it to a function (like rawurldecode()). I found reports on similar issues in the bug database
(bugs #330, #349 and #350), but they could not give me a valid hint. Then I read through some PHP source code, 
especially the function "void PHP3_UODBC_RESULT(INTERNAL_FUNCTION_PARAMETERS)" in file functions/unified_odbc.c, 
and I found out the following:
1. In line 1340 of unified_odbc.c, the data are returned via RETURN_STRINGL, but with duplicate set to 0. May, for some 
reason I could not figure out, this lead to an empty return string?
2. The passthru dump to the client is done in line 1382 (PHPWRITE...), and the function's return code is set via 
RETURN_TRUE - which results in a '1' if I use echo to output it. This part of code should only be reached if the preceding
switch()-block did not reach a RETURN_..., and with my "parameters" (field type LONGVARCHAR (I checked it!), 
binmode=2 and longreadlen=4096 (but the same with any other setting...), the code after the switch() block IS not reached;
it should execute the RETURN_STRINGL in line 1340. 
So I suspect the following: binmode and longreadlen are always 0 - they are initialized to these values in 
"int PHP3_RINIT_UODBC(INIT_FUNC_ARGS)" in line 298 and 299. 
"void php3_uodbc_fetch_attribs(INTERNAL_FUNCTION_PARAMETERS, int mode)", starting in line 474, should set them
to different values, but presumably does not.

The reason for the infinite output that occurs when I try to read the LONGVARCHAR field a second time may lie somwhere
in the ODBC driver - I suppose it does not reset some internal pointer. But that's not the problem - once I got it assigned
to a variable, I do not need to read it again.

So I hope this information helps you to find out, why PHP behaves this way.

Best regards, and thanks in advance
Michael Woecherl


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [1998-06-24 11:05 UTC] kara
uodbc.defaultlrl and uodbc.defaultbinmode from php.ini were not used.
This has been fixed. The defaults for uodbc.defaultlrl and
uodbc.defaultbinmode have been changed so that LONG fields get returned
to php variables up to 4k by default.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Apr 08 16:01:25 2020 UTC