[freetds] String comparisons not working correctly, FreeTDS + PHP + MSSQL 2005

Federico Cáceres fede.caceres at gmail.com
Wed Apr 30 09:44:51 EDT 2008

Hello, I am using freetds along with PHP in a CentOS 5.0 machine.

I installed freetds and php-mssql without any problems thanks to yum,
which took care of downloading and installing both packages for me.
Then I added my host to freeTDS's config file and everything went
"marvellously", all my queries work and I was just happy everything
went so smoothly!

Suddenly, a day after the installation, some of my php queries where
not working. Later on I discovered it had something to do with the
string columns, seems like freetds was grabbing the maximun length of
the column, instead of the used length.

Let me give you an example:
column "UweName" is  of type nvarchar(15),
if I run sometying like

I get no results, even if I have actually populated the database with
an entry with that name.

So, I deleted the WHERE clause, and used php's var_dump function on
each row that was retrieved from the database. And this is what i got:
"UweName" => "Fred           " (The actual value, and trailing spaces
to fill the 15 characters of the column).

This is odd, specially because one day before the queries where
working marvellously (I discovered too that the MSSQL server was shut
down during the whole night after the installation and powered back on
the next morinng... the same morning in which these problems

So, any ideas on what can be happening? Because now I'm about to do
some ugly hacking on my queries to get these working... and I'm not
happy with those.

Software versions:
PHP 5.1.6.
FreeTDS .064
Microsoft SQL Server 2005 on a Windows machine.

Thank you very much for your assistance!!!

More information about the FreeTDS mailing list