Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.9.3

Bug #502 [PATCH] FreeTDS-Compatible DB_mssql::tableInfo()
Submitted: 2003-12-29 22:30 UTC
From: thomas at unifiedconsulting dot com Assigned:
Status: Bogus Package: DB
PHP Version: 4.3.4 OS: Linux
Roadmaps: (Not assigned)    
Subscription  


 [2003-12-29 22:30 UTC] thomas at unifiedconsulting dot com
Description: ------------ The current DB_mssql::tableInfo() uses mssql_field_name(), mssql_field_type() and mssql_field_length() to get field information. These functions don't work when using FreeTDS/Sybase extensions. The patch below uses mssql_fetch_field() instead, which I believe should work with both FreeTDS and php_mssql.dll. Note that I haven't tested that it works on Windows, since I don't have a Windows-based PHP installation readily available. ---cut here--- Index: mssql.php =================================================================== RCS file: /repository/pear/DB/DB/mssql.php,v retrieving revision 1.19 diff -u -r1.19 mssql.php --- mssql.php 5 Dec 2003 22:00:14 -0000 1.19 +++ mssql.php 29 Dec 2003 22:04:31 -0000 @@ -493,9 +493,12 @@ for ($i=0; $i<$count; $i++) { $res[$i]['table'] = (is_string($result)) ? $result : ''; - $res[$i]['name'] = @mssql_field_name($id, $i); - $res[$i]['type'] = @mssql_field_type($id, $i); - $res[$i]['len'] = @mssql_field_length($id, $i); + + $fieldInfo=mssql_fetch_field($id,$i); + $res[$i]['name'] = $fieldInfo['name']; + $res[$i]['type'] = $fieldInfo['type']; + $res[$i]['len'] = $fieldInfo['max_length']; + // We only support flags for tables $res[$i]['flags'] = is_string($result) ? $this->_mssql_field_flags($result, $res[$i]['name']) : ''; } @@ -505,10 +508,13 @@ for ($i=0; $i<$count; $i++) { $res[$i]['table'] = (is_string($result)) ? $result : ''; - $res[$i]['name'] = @mssql_field_name($id, $i); - $res[$i]['type'] = @mssql_field_type($id, $i); - $res[$i]['len'] = @mssql_field_length($id, $i); - // We only support flags for tables + + $fieldInfo=mssql_fetch_field($id,$i); + $res[$i]['name'] = $fieldInfo['name']; + $res[$i]['type'] = $fieldInfo['type']; + $res[$i]['len'] = $fieldInfo['max_length']; + + // We only support flags for tables $res[$i]['flags'] = is_string($result) ? $this->_mssql_field_flags($result, $res[$i]['name']) : ''; if ($mode & DB_TABLEINFO_ORDER) { $res['order'][$res[$i]['name']] = $i; ---cut here---

Comments

 [2003-12-29 23:27 UTC] thomas at unifiedconsulting dot com
My bad, the fieldInfo lines are actually totally wrong. $fieldInfo['name'] should actually be $fieldInfo->name, and the same for type and max_length
 [2003-12-30 05:03 UTC] fmk at php dot net
You should compile php using --with-mssql. Using --with-sybase only provides a subset of the MSSQL functions (aliases to the sybase_functions). Patching DB::mssql to match the limited function set available in the Sybase extension does not make any sence to me.
 [2003-12-30 05:19 UTC] thomas at unifiedconsulting dot com
One way works with both --with-mssql and --with-sybase. The other way works only with --with-mssql. Not everyone has full control over their build environment. The choice seems clear to me, but I'm not the package maintainer.