ODBC returns correct # of rows, but no data?

From: Date: Mon, 14 May 2001 18:01:21 +0000
Subject: ODBC returns correct # of rows, but no data?
Groups: php.db 
Request: Send a blank email to php-db+get-9306@lists.php.net to get a copy of this message
I have a MSSQL server running on WinNT, and I am trying to issue queries to it from my Linux 2.2.17 system using ODBC. I have installed unixODBC and the FreeTDS driver, and with this combination I am able to send queries from a command line client succesfully. In particular, when I execute the query in the PHP script below, I get exactly 593 rows, as expected. When I execute the script below, I count the number of rows inside the loop, and print it out after displaying the HTML table containing all of the rows. The number of rows is 593, as expected. However, the table is blank! No data was printed! Viewing the source shows 593 copies of: <TR> <TD></TD> <TD></TD> </TR> What gives? The query is obviously executing, and is returning the right number of rows, but it isn't giving me the row data. To make things worse, about 1 in 5 runs of this script returns "Document contains no data" and the following line in the error_log: [Mon May 14 12:24:16 2001] [notice] child pid 14627 exit signal Segmentation fault (11) FATAL: emalloc(): Unable to allocate 137579345 bytes Here is the script. It is a simple script to test the ODBC functions. It executes a two-column SELECT and displays the result in a table. It does not seem to matter whether I pass the field names or the column position to the odbc_result() function. Both return blank (""). <? $db = odbc_connect("TEST","",""); if(!$db) { echo "odbc_connect() failed\n"; exit; } $handle = odbc_prepare($db,"SELECT acctid,company FROM account"); if(!$handle) { echo "odbc_prepare() failed\n"; exit; } if(!odbc_execute($handle)) { echo "odbc_execute() failed\n"; exit; } ?> <TABLE BORDER> <!-- This row comes out blank, also. --> <TR> <TD><? echo htmlspecialchars($c1 = odbc_field_name($handle,1)) ?></TD> <TD><? echo htmlspecialchars($c2 = odbc_field_name($handle,2)) ?></TD> </TR> <? } while(odbc_fetch_row($handle)) { $c++; $k = odbc_result($handle,1); $v = odbc_result($handle,2); ?> <TR> <TD><? echo htmlspecialchars($k) ?></TD> <TD><? echo htmlspecialchars($v) ?></TD> </TR> <? } echo "</TABLE>\n"; odbc_free_result($handle); odbc_close($db); ?> <HR> <? echo $c ?> rows.

« previous php.db (#9306) next »