Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP odbc_result() appears to be returning random uninitialized memory for varchar fields in 5.5+; identical code working in 5.4

I'm using an ODBC connection to retrieve data on a Windows Server. After upgrading PHP from 5.4 to 5.6 (as well as on 5.5) all varchar fields seem to be returning random uninitialized memory, although the string length does match that of the field being queried.

For example, a query returning the string "Test.txt" in 5.4 returns the following in 5.5+:

garbled

I've compared my php.ini settings between the two versions and they seem to be identical in terms of what's being specific related to charsets and ODBC settings.

I can run both versions side by side on the same ODBC resource at the same time and get these results. Non-varchar fields like dates and integers are printing correctly. I'm simply running the x86 thread safe php.exe executable downloaded from http://windows.php.net/download for 5.4, 5.5, and 5.6.

What else can I configure to try and resolve this?

Edit: I'm using the Unified ODBC functions like so:

$o = odbc_connect("Driver=MMODBC;Server=localhost;Database=odbc_mapping;", [user], [pass]);
$r = odbc_exec($o, "SELECT * FROM Table");
while (odbc_fetch_row($r)) {
    print odbc_result($r, 1);
}
like image 908
Charlie Schliesser Avatar asked Jun 10 '16 19:06

Charlie Schliesser


1 Answers

There are a handful of bugs at http://bugs.php.net related to uninitialized data appearing in odbc function results. They are primarily for older (e.g. 5.3) versions of php. That appears to be what's happening in this case, or some variant therein.

Switching to PDO in 5.6 has completely resolved the issue for me.

like image 84
Charlie Schliesser Avatar answered Nov 12 '22 03:11

Charlie Schliesser