Ronny Grønsdal
Ronny Grønsdal

Reputation: 21

Undefined Property and PHP Fatal Error: Allowed memory exhausted when querying mssql from php through unixODBC/FreeTDS

After upgrading php from version 5.2.10 to 5.3.3 I am getting a very strange set of errors when using odbc queries that works fine in 5.2.10.

I get a lot of Undefined Property: stdClass::$username finally ending in a Memory Exhaust Allowed error when I run queries like the following:

    $conn = odbc_connect("dsn", "user", "pw") or die(odbc_error_msg()); 

    $query = "select usr_n as username from usr";
    $rs = odbc_exec($conn,$query);

    while ($rows = odbc_fetch_object($rs)) {
        echo "$rows->username";
        }
    odbc_free_result($rs);
    odbc_close($conn);

the strange part is that if I run this code without the 'username' alias and use the table name as shown in the query underneath, it works fine:

    $conn = odbc_connect("dsn", "user", "pw") or die(odbc_error_msg()); 

    $query = "select usr_n from usr";
    $rs = odbc_exec($conn,$query);

    while ($rows = odbc_fetch_object($rs)) {
        echo "$rows->usr_n";
        }
    odbc_free_result($rs);
    odbc_close($conn);

also if I use alias with a count(*) statement it works fine, but as soon as I replace a tablename with an alias it all goes wrong.

I tried the query in iSQL with the alias, and it works like it is supposed to, so the unixODBC and FreeTDS is working.

I have searched through all the material I could find both here and google, but havent got any answer to why this is happening.

Appreciate it if anyone here has an idea to what is going on here, as it seems to me to have something to do with aliases and I use aliases a lot.

BTW: Upgrading php is sadly not an option for me.

Upvotes: 1

Views: 537

Answers (1)

maxxs
maxxs

Reputation: 1

In my case the problem was accented characters (spanish). I solved this adding Collate SQL_Latin1_General_CP1253_CI_AI to every field with this chars on every SELECT.

Upvotes: 0

Related Questions