PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Database » DB » Bug #5406

DB_FETCHMODE_ASSOC don't works with MSSQL

Details

Submitted2005-09-14 22:13 UTC
Fromleonardo at absbrasil dot com
Assigneddanielc
StatusDuplicate
PackageDB
PHP Version4.3.11
OSLinux
Roadmaps(Not assigned)

Comments

[2005-09-14 22:13 UTC] leonardo at absbrasil dot com

Description:
------------
Using :
DB version 1.7.6
MSSQL Server 2000

When performing a simple query on MSSQL database and set up DB_FETCHMODE_ASSOC to fetching the result its return a NULL value.

I fix it removing the second parameter the is passed in mssql_fetch_array() function.

ie on line 320 inside of fetchInto() method.

The second parameter is no needed, only old php versions it's possible.

Test script:
---------------
/*
require_once 'DB.php';

$sql = "SELECT top 100 * from myTable";
$dsn = "mssql://user:pass@myhost:1433/MyDB";

$db = &DB::connect($dsn);

$res = $db ->query($sql);

$res->fetchInto($row, DB_FETCHMODE_ASSOC);

var_dump($row);

*/

Expected result:
----------------
a associative array with result

Actual result:
--------------
a null value

[2005-09-15 01:59 UTC] leonardo at absbrasil dot com

if ($fetchmode & DB_FETCHMODE_ASSOC) {
- $arr = @mssql_fetch_assoc($result);
+ /* If php was compiled with sybase_ct support */
+ if(function_exists('mssql_fetch_assoc')){
+ $arr = @mssql_fetch_assoc($result);
+ } else {
+ /* This is bad because a double array is returned (ORDERED AND ASSOC ) */
+ $arr = @mssql_fetch_array($result);
+ }
if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
$arr = array_change_key_case($arr, CASE_LOWER);
}