|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55291 All ODBC Queries Return INTs as Strings For Multiple ODBC Drivers
Submitted: 2011-07-26 21:44 UTC Modified: 2011-12-01 05:35 UTC
Avg. Score:4.8 ± 0.6
Reproduced:7 of 8 (87.5%)
Same Version:6 (85.7%)
Same OS:5 (71.4%)
From: brandonkirsch at gmail dot com Assigned:
Status: Not a bug Package: ODBC related
PHP Version: 5.3.6 OS: SUSE SLES 10 SP2
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.
Bug Type:
From: brandonkirsch at gmail dot com
New email:
PHP Version: OS:


 [2011-07-26 21:44 UTC] brandonkirsch at gmail dot com
odbc_* and PDO ODBC functions are each returning SQL integer values as PHP 
strings. However, SQL NULL values properly appear as PHP NULL values.

I have tested against multiple ODBC providers (FreeTDS and iSeries Access for 


SUSE Enterprise Linux Server 10 (SP2) - 32bit

Linux dev-webhost1 #1 Mon Aug 24 09:41:41 UTC 2009 i686 
i686 i386 GNU/Linux


PHP 5.3.6 from source

./configure  --with-apxs2=/usr/local/apache2/bin/apxs --with-
mssql=/usr/local/freetds --with-ldap --prefix=/usr/local/php5 --with-config-
path=/usr/local/php5/etc --enable-sockets --enable-soap --with-openssl --with-
unixODBC=/usr --with-gd --with-jpeg-dir=/usr/lib --with-pdo-odbc=unixODBC,/usr

Test script:
1. odbc_* against FreeTDS to SQL Server 2008:

$odbc = odbc_connect('hpsql3','--censored--','--censored--');
$or = odbc_exec($odbc,'SELECT 1');
var_dump(odbc_fetch_array($or)); // array( string "1" )

2. odbc_* against iSeries Access for Linux to AS/400:

$odbc = odbc_connect('iSeriesDSN','--','--');
$or = odbc_exec($odbc,'SELECT 1 FROM SYSIBM.SYSDUMMY1');
var_dump(odbc_fetch_array($or)); // array( string "1" )

3. PDO against FreeTDS to SQL Server 2008

$pdo = new PDO('odbc:hpsql3','--','--');
var_dump($pdo->query('SELECT 1')->fetch(PDO::FETCH_ASSOC)); // array (string "1")

4. PDO against iSeries Access for Linux to AS/400

$pdo = new PDO('odbc:iSeriesDSN','--','--');
var_dump($pdo->query('SELECT 1 FROM SYSIBM.SYSDUMMY1')->fetch(PDO::FETCH_ASSOC)); // array (string "1")

Expected result:
I expect to get arrays containing (int) 1

Actual result:
I actually get arrays containing (string) "1"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-12-01 05:35 UTC]
-Status: Open +Status: Bogus
 [2011-12-01 05:35 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

Most database layers convert numeric values to strings to preserve their precision as PHP does not support all numeric precisions which a database might (i.e. 64 bit integers). Since strings may be silently converted to numeric in PHP ("1" + 2 = 3), this should not pose too much of an issue.
 [2012-02-07 08:50 UTC] martijntje at martijnotto dot nl
I have no idea why this bug is closed as bogus.

The current behavior is wrong for many reasons:
- Higher memory usage (can be problematic with big datasets)
- This forces one to use is_numeric instead of is_int, is_float, etc (much slower)
- Removed the option for strict comparison: "1" === 1 => false
 [2012-09-10 23:30 UTC] brandonkirsch at gmail dot com
FYI - For those of you still struggling with this "Not a bug" - there are 
functions available (odbc_field_type, mssql_field_type) that can help you re-cast 
your database numerics back to their correct types in PHP.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Tue May 17 04:05:45 2022 UTC