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:
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","","");
echo "odbc_connect() failed\n";
$handle = odbc_prepare($db,"SELECT acctid,company FROM account");
echo "odbc_prepare() failed\n";
echo "odbc_execute() failed\n";
<!-- This row comes out blank, also. -->
<TD><? echo htmlspecialchars($c1 = odbc_field_name($handle,1)) ?></TD>
<TD><? echo htmlspecialchars($c2 = odbc_field_name($handle,2)) ?></TD>
$k = odbc_result($handle,1);
$v = odbc_result($handle,2);
<TD><? echo htmlspecialchars($k) ?></TD>
<TD><? echo htmlspecialchars($v) ?></TD>
<? echo $c ?> rows.