|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63949 selects on long varchar fields returns empty with PDO ODBC
Submitted: 2013-01-09 00:27 UTC Modified: 2020-10-11 04:22 UTC
Avg. Score:4.9 ± 0.4
Reproduced:27 of 27 (100.0%)
Same Version:5 (18.5%)
Same OS:4 (14.8%)
From: toebs at pubsqrd dot com Assigned: cmb (profile)
Status: No Feedback Package: PDO ODBC
PHP Version: 5.4.10 OS: Amazon Linux
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: toebs at pubsqrd dot com
New email:
PHP Version: OS:


 [2013-01-09 00:27 UTC] toebs at pubsqrd dot com
In short, it looks like selects on varchars columns which are long (some indeterminate value, 1000 certainly qualifies) fail with PDO via ODBC.

The same query works with the following methods;

1. PDO using mysql
2. unixODBC directly (via isql)
3. vsql (the Vertica native command line client)

The error given is that column binding has not occurred.  This is odd - note in the script I have deliberately used fetchColumn() to avoid the need for column binding, in an effort to avoid this error.

This problem was found in 5.3.19 and also in 5.4.9.

Test script:
create table tobytest
  string_short varchar(50),
  string_long varchar(1000)

insert into tobytest (string_short, string_long) values ('short', 'long');


$db_connect = new PDO( "odbc:pubsquared", "dbadmin", "big science" );
$db_connect -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$q = $db_connect->prepare( "select string_long from tobytest" );

$r = $q->fetchColumn();
print $r;


Expected result:
[root@ip-1-1-1-1 ~]# php test4.php
[root@ip-1-1-1-1 ~]#

Actual result:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[SL010]: <<Unknown error>>: 0 [unixODBC][Driver Manager]SQLBindCol returned SQL_ERROR on a attempt to bind a internal buffer (SQLFetchScroll[0] at /builddir/build/BUILD/php-5.4.9/ext/pdo_odbc/odbc_stmt.c:537)' in /root/test4.php:8
Stack trace:
#0 /root/test4.php(8): PDOStatement->fetchColumn()
#1 {main}


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-01-09 08:41 UTC] toebs at pubsqrd dot com
-: toes at pubsqrd dot com +: toebs at pubsqrd dot com
 [2013-01-09 08:41 UTC] toebs at pubsqrd dot com
Typo in the email address.  Correct email is "".
 [2013-01-30 00:08 UTC] paul dot posts at gmail dot com
Also seeing this using pdo+odbc with MSSQL 2012. varchar(max) and varchar(256) 
columns were both causing heap overflow. Casting the columns to a text column 
resulted in returning the correct data as a workaround.
 [2013-01-30 00:38 UTC] paul dot posts at gmail dot com
Apologies, our testing showed that cast to text was not a viable workaround.
 [2013-02-20 06:22 UTC] cyberitas at gmail dot com
We're also seeing the same sigsegv mentioned in the previous comment with pdo+odbc 
with MS-SQL via freetds ODBC.  Selecting from a column defined as varchar(256) any 
of the fetch functions lead to a segfault. 

Program received signal SIGSEGV, Segmentation fault.
0x00002aaab393010b in ?? () from /usr/lib64/
(gdb) info stack
#0  0x00002aaab393010b in ?? () from /usr/lib64/
#1  0x00002aaab013648d in SQLGetData () from /usr/lib64/
#2  0x00002aaab059d288 in ?? () from /usr/lib64/php/modules/
#3  0x00002aaab038d920 in ?? () from /usr/lib64/php/modules/
#4  0x00002aaab038e56e in ?? () from /usr/lib64/php/modules/
#5  0x00002aaab038f7fc in ?? () from /usr/lib64/php/modules/
#6  0x00000000005e78e9 in ?? ()
#7  0x00000000005bd9ab in execute ()
#8  0x0000000000599f45 in zend_execute_scripts ()
#9  0x000000000054ad48 in php_execute_script ()
#10 0x0000000000622cde in ?? ()
#11 0x00000034b5e1d9c4 in __libc_start_main () from /lib64/
#12 0x0000000000421789 in _start ()
 [2014-01-01 12:34 UTC]
-Package: PDO related +Package: PDO ODBC
 [2017-04-14 18:42 UTC] daniel at ringhisercomputersolutions dot com
This problem still exists in version 7.0.15. Why is this not being fixed?
 [2018-05-30 19:11 UTC] ivaldo dot oliveira at gmail dot com
This problem still exists in version 7.2.2. My column is varchar (300) and my database is the Intersystems Cache.
Thanks for help.
 [2020-09-28 13:54 UTC]
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2020-09-28 13:54 UTC]
I cannot reproduce this with current PHP 7.3 and the ODBC Driver
17 for SQL Server.  Can anybody else reproduce the segfault with
any of the actively supported PHP versions[1]?  If so, we need to
know which database and ODBC driver, and which version of PHP you
are using, and also an ODBC trace of the execution of a well
defined script.

[1] <>
 [2020-10-11 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Oct 20 21:01:23 2020 UTC