[freetds] Unicode problem

Vano Beridze vano.beridze at silkroad.ge
Tue Sep 3 06:56:54 EDT 2013


I've got windows 7 machine that runs SQL Server Express 2008  R2.
I've some table with nvarchar field that contains unicode data.

Another linux (CentOS 6.4) machine runs Apache 2.2 with php 5.3.3.
freetds version is 0.91

This is the /etc/freetds.conf file
         # TDS protocol version
         tds version = 8.0
         port = 1433
         client charset = UTF-8
         # Whether to write a TDSDUMP file for diagnostic purposes
         # (setting this to /tmp is insecure on a multi-user system)
         dump file = /tmp/freetds.log
         debug flags = 0x4fff

         # Command and connection timeouts
         timeout = 180
         connect timeout = 180

         # If you get out-of-memory errors, it may mean that your client
         # is trying to allocate a huge buffer for a TEXT field.
         # Try setting 'text size' to a more reasonable limit
         text size = 20971520

I've created simple php script that connects to sql server and reads 
data from that table (actually there is a view to hide unnecessary fields)

Here is the php script
echo "<html><head>";
echo '<meta http-equiv="Content-type" content="text/html; charset=utf-8" 
echo "</head>";
echo "<body>";
echo "<h1>Hello</h1>";
$connect = odbc_connect("server", "someuser", "somepass");

if (!$connect) {
echo '<h3 color="red">Could not connect to the database!!!</h3>';

# query the users table for all fields
$query = "SELECT odf_address FROM dbo.odf";

# perform the query
$result = odbc_exec($connect, $query);

# fetch the data from the database
while(odbc_fetch_row($result)) {
#$field1 = odbc_result($result, 1);
$field2 = odbc_result($result, 1);
#echo $field1;
#echo "<br>";
echo $field2;
echo "<br>";

# close the connection
echo "</body></html>";

The script works fine. it connects and gets the data. The only problem I 
have is that data is shown as question marks, so it's not converted to 
UTF-8. I've read all the information I could find on the internet but 
can not solve the problem.

Could you please suggest what's the problem?

Vano Beridze
Software Developer
Silk Road Group

More information about the FreeTDS mailing list