Home » Database » DB » Bug #1525
DB_FETCHMODE_ASSOC doesn't work with MSSQL
Details
| Submitted | 2004-05-28 14:28 UTC |
|---|---|
| From | tricera_it at yahoo dot it |
| Assigned | danielc |
| Status | Bogus |
| Package | DB |
| PHP Version | 4.3.4 |
| OS | Linux |
| Roadmaps | (Not assigned) |
Comments
[2004-05-28 14:28 UTC] tricera_it at yahoo dot it
Description:
------------
With MSSQL, if you try to fetch results with DB_FETCHMODE_ASSOC or DB_FETCHMODE_OBJECT you will get no loop.
DB_FETCHMODE_ORDERED works properly.
Reproduce code:
---------------
With MSSQL, this works:
$db->setFetchMode(DB_FETCHMODE_ORDERED);
$res =& $db->query('SELECT * FROM users');
while ($row =& $res->fetchRow()) {
echo $row['id'] . "\n";
}
this not:
$db->setFetchMode(DB_FETCHMODE_ASSOC);
$res =& $db->query('SELECT * FROM users');
while ($row =& $res->fetchRow()) {
echo $row['id'] . "\n";
}
Determining fetch mode per call gives the same problem.
[2004-05-28 15:09 UTC] tricera_it at yahoo dot it
Version 1.6.4
[2004-05-28 22:13 UTC] tricera_it at yahoo dot it
You are right: my example is bugged :-(
But was just a copy & paste error. I can assure you that if the following code works:
echo "start\n";
$res =& $db->query('SELECT * FROM users');
while ($row =& $res->fetchRow(DB_FETCHMODE_ORDERED)) {
echo "looping: ";
echo $row[0]."\n";
}
echo "end\n";
and returns:
start
looping: 1
looping: 2
(...)
end
the following doesn't work:
echo "start\n";
$res =& $db->query('SELECT * FROM users');
while ($row =& $res->fetchRow(DB_FETCHMODE_ASSOC)) {
echo "looping: ";
echo $row['id']."\n";
}
echo "end\n";
and returns:
start
end
so the loop is ignored. A case sensitivity problem should returns:
start
looping:
looping:
(...)
end
This happens only with MSSQL, and not, as eg., with MYSQL.
If it is an my error pls let me know how to solve it.
[2004-05-29 07:43 UTC] tricera_it at yahoo dot it
I've run the test. This is the result:
row count: 909
No error messages has been printed.
I've also extended the test as the following:
<?php
$res =& $db->query('SELECT * FROM users');
if (DB::isError($res)) {
echo $res->getUserInfo() . "\n";
exit;
}
echo 'row count: ' . $res->numRows() . "\n";
$row =& $res->fetchRow(DB_FETCHMODE_ASSOC);
if (DB::isError($row)) {
echo $row->getUserInfo() . "\n";
exit;
}
print_r($row);
$row =& $res->fetchRow(DB_FETCHMODE_ORDERED);
print_r($row);
?>
The result was:
row count: 909
Array
(
[0] => 1
[1] => John
[2] => Smith
)
I'd like to underline that all this happens ONLY with MSSQL, not with other databases.
[2004-05-29 10:40 UTC] tricera_it at yahoo dot it
I've found the solution!
It was a PHP problem and not a DB bug. PHP did not recognize the MSSQL_ASSOC parameter of mssql_fetch_array function (line 198 of mssql.php). I've removed the @ from that function to see the error message.
Now, installing the last release (4.3.6) of PHP, all seems to work properly.
Thank for your help.
[2004-05-29 17:01 UTC] tricera_it at yahoo dot it
Probably the problem was not due to the PHP version but to the PHP configuration. PHP 4.3.4 has been compiled with the option --with-sybase=[dir_to_FreeTDS], now I try to compile with --with-mssql=[dir_to_FreeTDS].
I think, but is just an idea, that this second way lets MSSQL_* constants be available.