php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #30043 ODBC Column Name Truncation (missing multi-byte support)
Submitted: 2004-09-09 22:08 UTC Modified: 2015-04-11 17:10 UTC
Votes:15
Avg. Score:4.8 ± 0.5
Reproduced:15 of 15 (100.0%)
Same Version:12 (80.0%)
Same OS:11 (73.3%)
From: arobins at csg dot uwaterloo dot ca Assigned: cmb (profile)
Status: Closed Package: *General Issues
PHP Version: 4CVS, 5CVS OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: arobins at csg dot uwaterloo dot ca
New email:
PHP Version: OS:

 

 [2004-09-09 22:08 UTC] arobins at csg dot uwaterloo dot ca
Description:
------------
When retrieving ODBC results from Sybase SQL Anywhere 6 and 9, the column names are being truncated to 31 characters. 

This happens even if the column name is simply specified using sql 'AS' (i.e. "select column as
a_really_long_name_that_is_longer_than_31_characters from crap" would still return "a_really_long_name_that_is_long" as the column name).

Have tried in PHP 4 and 5, Win2K Server and SUSE Linux, all with same results.

-- The buffer used by the odbc extension to store field
names is only 32 bytes.

Reproduce code:
---------------
<?php
$DBN = 'thedbn';
$UID = 'theuid';
$PWD = 'thepws';

$CONN = odbc_connect( $DBN, $UID, $PWD ) or die( "Cannot connect to
$DBN."); $sql = "select * from crap"; $result = odbc_exec( $CONN,
$sql );

for( $i = 1 ; $i <= odbc_num_fields( $result ) ; $i++ ) {
$name = odbc_field_name( $result, $i );
${$name} = odbc_result( $result, $name );
print( "$i: $name - ${$name}\n" );
}
?>


Expected result:
----------------
1: key - 4
2: a_really_long_name_that_is_longer_than_31_characters - 5
3: longer_name - 6


Actual result:
--------------
1: key - 4
2: a_really_long_name_that_is_long - 5
3: longer_name - 6


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-09-10 03:23 UTC] kalowsky@php.net
Known issue.  Was once looked into correct to provide 
true multi-byte support, but was side tracked.
 [2004-11-03 16:52 UTC] arobins at csg dot uwaterloo dot ca
Until 'true multi-byte support' comes along, might I suggest as a temporary solution simply increasing the field name buffer? (i.e. from 32 to 256)
 [2005-10-19 20:46 UTC] arobins at csg dot uwaterloo dot ca
It's been over a year since my original submission, and I was wondering if it would be at all possible for someone to implement an increase in the field name buffer from 32 to 256?

Only one line needs to be changed to accomplish this,
in ext\odbc\php_odbc_includes.h:
line 217: char name[32]; -> char name[256];

If it is at all possible for someone to make this minor modification for me, I would be extremely grateful!
 [2005-10-24 17:55 UTC] kalowsky@php.net
As stated in a private email, the biggest issue with such a change is how much it effects other databases beyond those that you have used.  It's a simple change, but it's unknown what databases will fail with this.
 [2005-10-24 18:29 UTC] wez@php.net
You could try PDO + PDO_ODBC as an alternative.
 [2005-10-24 20:31 UTC] kalowsky@php.net
As PDO gains more and more traction that's probably the best idea
 [2006-02-17 16:14 UTC] bobbyboyojones at hotmail dot com
PDO + PDO_ODBC seems to have a similar issue, only it seems to experience a fatal error when it runs into long column names.  I have tried the solution of changing the field name buffer from 32 to 256 in the odbc_result_value typedef struct, and everything has been working fine with all of the databases I've tried it against.
 [2015-04-11 17:10 UTC] cmb@php.net
-Status: Open +Status: Closed -Package: Feature/Change Request +Package: *General Issues -Assigned To: +Assigned To: cmb
 [2015-04-11 17:10 UTC] cmb@php.net
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at 
http://www.php.net/downloads.php

Fixed as of PHP 5.4.0.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 12:01:27 2024 UTC